zoukankan      html  css  js  c++  java
  • Petr and Permutations CodeForces

    题意:

      给出一个长度为n的序列,求出是谁操作的(原序列为从小到大的序列),Peter的操作次数为3n,Alex的操作次数为7n+1

    解析:

      我们来看这个序列中的逆序对,逆序对的个数为偶数则操作次数为偶数,逆序对的个数为奇数,则操作次数为奇数

    然后树状数组求逆序对即可

    #include <bits/stdc++.h>
    #define mem(a, b) memset(a, b, sizeof(a))
    using namespace std;
    const int maxn = 1e6+10, INF = 0x7fffffff;
    int c[maxn];
    int n;
    int lowbit(int x)
    {
        return x & (-x);
    }
    
    void add(int x, int y)
    {
        for(int i=x; i<=n; i+=lowbit(i))
            c[i] += y;
    }
    
    int get_sum(int x)
    {
        int res = 0;
        for(int i=x; i>0; i-=lowbit(i))
            res += c[i];
        return res;
    }
    
    int main()
    {
        int x;
        int res = 0;
        cin>> n;
        for(int i=0; i<n; i++)
        {
            cin>> x;
            int ans = get_sum(x);
            res += i - ans;
            add(x, 1);
        }
        int a = 3 * n, b = 7 * n + 1;
        if(res & 1)
        {
            if(a & 1)
                cout<< "Petr" <<endl;
            else
                cout<< "Um_nik" <<endl;
        }
        else
        {
            if(a & 1)
                cout<< "Um_nik" <<endl;
            else
                cout<< "Petr" <<endl;
        }
    
        return 0;
    }
    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    洛谷 P1200.[USACO1.1]你的飞碟在这儿Your Ride Is Here
    洛谷 P1055.ISBN号码
    洛谷 P1567.统计天数
    洛谷 P2141.珠心算测验
    洛谷 P1428.小鱼比可爱
    洛谷 P1427.小鱼的数字游戏
    洛谷 P1047.校门外的树
    洛谷 P1046.陶陶摘苹果
    洛谷 P1980.计数问题
    洛谷 P1424.小鱼的航程(改进版)
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/9524621.html
Copyright © 2011-2022 走看看