Codeforces 986B. Petr and Permutations(没想到这道2250分的题这么简单,早知道就先做了)
生活随笔
收集整理的這篇文章主要介紹了
Codeforces 986B. Petr and Permutations(没想到这道2250分的题这么简单,早知道就先做了)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
這題真的只能靠直覺了,我沒法給出詳細證明。
解題思路:
1.交換3n次或者7n+1次,一定會出現(xiàn)一個為奇數(shù),另一個為偶數(shù)。
2.用最樸素的方法,將n個數(shù)字歸位,計算交換次數(shù)。
3.判斷交換次數(shù)是否與3n的奇偶性相同,相同輸出Petr;
不相同則一定與7n+1的奇偶性相同,輸出Um_nik。
code:
#include <bits/stdc++.h> using namespace std; typedef long long ll;int a[1000010]; int idx[1000010]; int main(){ios::sync_with_stdio(false);int n;cin >> n;for(int i = 1;i <= n; ++i) cin >> a[i],idx[a[i]] = i;int cot = 0;for(int i = 1;i <= n; ++i){if(a[i] != i){a[idx[i]] = a[i];idx[a[i]] = idx[i];cot++;}}if((cot+3*n)&1){cout << "Um_nik" << endl;}else{cout << "Petr" << endl;}return 0; }總結
以上是生活随笔為你收集整理的Codeforces 986B. Petr and Permutations(没想到这道2250分的题这么简单,早知道就先做了)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Codeforces 987C. Thr
- 下一篇: Codeforces 986A. Fai