题意:

  给出一个长度为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+, 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 = ;
for(int i=x; i>; i-=lowbit(i))
res += c[i];
return res;
} int main()
{
int x;
int res = ;
cin>> n;
for(int i=; i<n; i++)
{
cin>> x;
int ans = get_sum(x);
res += i - ans;
add(x, );
}
int a = * n, b = * n + ;
if(res & )
{
if(a & )
cout<< "Petr" <<endl;
else
cout<< "Um_nik" <<endl;
}
else
{
if(a & )
cout<< "Um_nik" <<endl;
else
cout<< "Petr" <<endl;
} return ;
}

Petr and Permutations CodeForces - 987E(逆序对)的更多相关文章

  1. CodeForces - 987E Petr and Permutations (思维+逆序对)

    题意:初始有一个序列[1,2,...N],一次操作可以将任意两个位置的值互换,Petr做3*n次操作:Alxe做7*n+1次操作.给出最后生成的新序列,问是由谁操作得到的. 分析:一个序列的状态可以归 ...

  2. CF986B Petr and Permutations [逆序对]

    题目传送门 Petr and Permutations 格式难调,题面就不放了. 分析: 胡乱分析+猜测SP性质一波.然后被学长告知:“1~n的排列交换次数与逆序对的奇偶性相同.”然后就愉快地A了. ...

  3. Codeforces 987E Petr and Permutations(数组的置换与复原 、结论)

    题目连接: Petr and Permutations 题意:给出一个1到n的序列,Petr打乱了3n次,Um_nik打乱了7n+1次,现在给出被打乱后的序列,求是谁打乱的. 题解:因为给出了一个3* ...

  4. Codeforces 987 K预处理BFS 3n,7n+1随机结论题/不动点逆序对 X&Y=0连边DFS求连通块数目

    A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_bac ...

  5. Codeforces Round #329 (Div. 2) B. Anton and Lines 逆序对

    B. Anton and Lines Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/pr ...

  6. codeforces 459D - Pashmak and Parmida&#39;s problem【离散化+处理+逆序对】

    题目:codeforces 459D - Pashmak and Parmida's problem 题意:给出n个数ai.然后定义f(l, r, x) 为ak = x,且l<=k<=r, ...

  7. Codeforces Round #485 (Div. 2) E. Petr and Permutations

    Codeforces Round #485 (Div. 2) E. Petr and Permutations 题目连接: http://codeforces.com/contest/987/prob ...

  8. Codeforces 351B Jeff and Furik:概率 + 逆序对【结论题 or dp】

    题目链接:http://codeforces.com/problemset/problem/351/B 题意: 给你一个1到n的排列a[i]. Jeff和Furik轮流操作,Jeff先手. Jeff每 ...

  9. 【Codeforces 986B】Petr and Permutations

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] n为奇数时3n和7n+1奇偶性不同 n为偶数时也是如此 然后交换任意一对数 逆序对的对数的奇偶性会发生改变一次 求出逆序对 对n讨论得出答案. ...

随机推荐

  1. Python中的dict字典的用法

    Python中的字典特点: 速度快,内部使用二分查找的方式 可以用来存储大量的关系型数据 字典是无序的 字典的定义方式: dic = dict(name =”zhangsan”,  age = 19) ...

  2. docker-compose 部署 EFK

    信息: Docker版本($ docker --version):Docker版本18.06.1-ce,版本e68fc7a 系统信息($ cat /etc/centos-release):CentOS ...

  3. MD5加密简单使用

    MD5加密简单使用规则 先写一个加密的工具类吧! public class MD5Util { public static String encoderPassword(String s) throw ...

  4. 【snaptype nexus】搭建maven私服仓库

    搭建本地开发私库,旨在解决本地开始受限于网络环境的问题:具体的搭建步骤主要包含以下几个步骤: 1.私服服务器使用的是ubuntu,首先下载安装包(版本号:2.12),下载地址:http://www.s ...

  5. yocto-sumo源码解析(一): oe-init-build-env

    oe-init-build-env是yocto构建环境运行的第一个脚本,通过运行下面的命令: . oe-init-build-env build-arm64 即可对yocto项目进行构建,顾名思义,该 ...

  6. CentOS7安装VMware Tools

    安装依赖包 [root@localhost ~]# yum -y install perl gcc gcc-c++ make cmake kernel kernel-headers kernel-de ...

  7. 程序设计 之 C#实现《拼图游戏》 (上)代码篇

    原理详解请参考博客中 拼图游戏(下)原理篇 http://www.cnblogs.com/labixiaohei/p/6713761.html 功能描述: 1.用户自定义上传图片 2.游戏难度选择:简 ...

  8. python3.6环境中django2.0与xadmin0.6结合的后台管理

    1.xadmin简介 django的admin管理后台页面很简洁,对个人来说做后台管理非常简单:xadmin的比较admin优化界面,看着也舒服. xadmin界面效果如下: 2.xadmin安装 从 ...

  9. mac 上面安装 tree 命令

    相信很多使用过Linux的用户都用过tree命令,它可以像windows的文件管理器一样清楚明了的显示目录结构. 但是mac下默认是没有 tree命令的. 1.我们可以使用find命令模拟出tree命 ...

  10. LeetCode 455. Assign Cookies (C++)

    题目: Assume you are an awesome parent and want to give your children some cookies. But, you should gi ...