0
点赞
收藏
分享

微信扫一扫

Problem - 986B - B. Petr and Permutations(排序的奇偶性)

Python芸芸 2022-02-26 阅读 40
算法

B. Petr and Permutations

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define syncfalse ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int N = 1e6+5;
int a[N], pos[N];
int main(){
    syncfalse
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    int n;
    cin>>n;
    for (int i = 1; i <= n; ++i){
        cin>>a[i];
        pos[a[i]]=i;
    }
    int cnt = 0;
    for (int i = n; i >= 1; --i){
        int id = pos[i];
        if (id==i)continue;
        else{
            int val = a[i];
            swap(a[i], a[id]);
            pos[i]=i;
            pos[val]=id;
            cnt++;
//            for (int i = 1; i <= n; ++i)cout << a[i] << " ";cout << "\n";
//            for (int i = 1; i <= n; ++i)cout << pos[i] << " ";cout << "\n";
        }
    }
    int change1 = n*3, change2 = n*7+1;
    if (cnt%2==change1%2)cout << "Petr\n";
    else cout << "Um_nik\n";

    return 0;
}
举报

相关推荐

0 条评论