• Codeforces 986B. Petr and Permutations(没想到这道2250分的题这么简单,早知道就先做了)


    这题真的只能靠直觉了,我没法给出详细证明。

    解题思路:

      1.交换3n次或者7n+1次,一定会出现一个为奇数,另一个为偶数。

      2.用最朴素的方法,将n个数字归位,计算交换次数。

      3.判断交换次数是否与3n的奇偶性相同,相同输出Petr;

        不相同则一定与7n+1的奇偶性相同,输出Um_nik。

    代码:

      

    #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;
    }
  • 相关阅读:
    Interesting Finds: 2008.06.12
    8月19号
    8月22号
    8月20号
    8月21号
    第七章 Nginx配置虚拟主机
    第六章 Nginx配置文件详解
    第五章 Nginx搭建上传作业平台
    sqlserver2005提供的xml数据类型操作xml串
    事必躬亲利与弊
  • 原文地址:https://www.cnblogs.com/zhangjiuding/p/9109977.html
Copyright © 2020-2023  润新知