CF986B Petr and Permutations 思维

每次交换:逆序对的数量+1或者-1;
假设最后逆序对数量为 sum;
①x+y=3n;
②x-y=sum;
-> 3n+sum为偶数;
所以 n 和 sum 必须奇偶一样;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 1000005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-4
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ int n;
int a[maxn];
int b[maxn];
int c[maxn]; void add(int x) {
while (x <= n) {
c[x]++; x += x & -x;
}
}
int query(int x) {
int res = 0;
while (x > 0) {
res += c[x]; x -= x & -x;
}
return res;
}
int main() {
//ios::sync_with_stdio(0);
rdint(n);
for (int i = 1; i <= n; i++) {
rdint(a[i]); b[i] = a[i];
}
sort(b + 1, b + 1 + n);
int ans = 0;
for (int i = 1; i <= n; i++) {
add(lower_bound(b + 1, b + 1 + n, a[i]) - b);
ans += (i - query(lower_bound(b + 1, b + 1 + n, a[i] + 1) - b - 1));
}
if ((ans & 1) == (n & 1)) {
cout << "Petr" << endl;
}
else cout << "Um_nik" << endl;
return 0;
}
CF986B Petr and Permutations 思维的更多相关文章
- CF986B Petr and Permutations [逆序对]
题目传送门 Petr and Permutations 格式难调,题面就不放了. 分析: 胡乱分析+猜测SP性质一波.然后被学长告知:“1~n的排列交换次数与逆序对的奇偶性相同.”然后就愉快地A了. ...
- CF986B Petr and Permutations
题意翻译 Petr要打乱排列.他首先有一个从 111 到 nnn 的顺序排列,然后进行 3n3n3n 次操作,每次选两个数并交换它们. Alex也要打乱排列.他与Petr唯一的不同是他进行 7n+17 ...
- CodeForces - 987E Petr and Permutations (思维+逆序对)
题意:初始有一个序列[1,2,...N],一次操作可以将任意两个位置的值互换,Petr做3*n次操作:Alxe做7*n+1次操作.给出最后生成的新序列,问是由谁操作得到的. 分析:一个序列的状态可以归 ...
- Codeforces Round #485 (Div. 2) E. Petr and Permutations
Codeforces Round #485 (Div. 2) E. Petr and Permutations 题目连接: http://codeforces.com/contest/987/prob ...
- Codeforces 987E Petr and Permutations(数组的置换与复原 、结论)
题目连接: Petr and Permutations 题意:给出一个1到n的序列,Petr打乱了3n次,Um_nik打乱了7n+1次,现在给出被打乱后的序列,求是谁打乱的. 题解:因为给出了一个3* ...
- Petr and Permutations CodeForces - 987E(逆序对)
题意: 给出一个长度为n的序列,求出是谁操作的(原序列为从小到大的序列),Peter的操作次数为3n,Alex的操作次数为7n+1 解析: 我们来看这个序列中的逆序对,逆序对的个数为偶数则操作次数为偶 ...
- 【Codeforces 986B】Petr and Permutations
[链接] 我是链接,点我呀:) [题意] 题意 [题解] n为奇数时3n和7n+1奇偶性不同 n为偶数时也是如此 然后交换任意一对数 逆序对的对数的奇偶性会发生改变一次 求出逆序对 对n讨论得出答案. ...
- Codeforces 986B. Petr and Permutations(没想到这道2250分的题这么简单,早知道就先做了)
这题真的只能靠直觉了,我没法给出详细证明. 解题思路: 1.交换3n次或者7n+1次,一定会出现一个为奇数,另一个为偶数. 2.用最朴素的方法,将n个数字归位,计算交换次数. 3.判断交换次数是否与3 ...
- Codeforces 986B - Petr and Permutations
Description\text{Description}Description Given an array a[], swap random 2 number of them for 3n or ...
随机推荐
- WINDOWS 7下的记事本程序目录
这是win7的目录 系统所在分区:\Windows\system32\notepad.exe
- phonegap 解决https访问问题
ios报错 在AppDelegate.m文件在最后加入(在@end后面加空行): @implementation NSURLRequest(DataController) + (BOOL)allows ...
- 简单的触发黑名单阻断演示 control+c
#include "stdafx.h"#include <signal.h>#include <windows.h> #include <iostre ...
- struts2学习笔记(2)action多个方法的动态调用
①在struts.xml中的action添加method <action name="addhelloworld" method="add" class= ...
- TCP/IP 笔记 7 Ping
lenovo-myc@lenovomyc-Lenovo-Product:~$ ping www.baidu.com PING www.a.shifen.com (() bytes of data. 这 ...
- sql中IN的用法
1.和where配合使用 IN操作符允许我们在where的子句中规定多个值 SELECT * FROM Persons WHERE LastName IN ('Adams','Carter') 这句 ...
- 使用线程池优化Echo模型
在上一篇文章中 http://www.cnblogs.com/gosaint/p/8492356.html 我阐述了使用线程为每一个客户端创建一个工作线程来负责任务的执行.但是会存在如 ...
- python 爬虫 常见安全措施
1.隐含输入字段值: 1.1首先采集表单所在页面上生成的随机变量,然后再提交到表单处理页面. 2.避免蜜罐 3.用远程服务器:洋葱路由(The Onion Router)网络.PySocks 是一个非 ...
- Guava Cache本地缓存
Guava介绍 Guava是一种基于开源的Java库,其中包含谷歌正在由他们很多项目使用的很多核心库. 这个库是为了方便编码,并减少编码错误. 这个库提供用于集合,缓存,支持原语,并发性,常见注解,字 ...
- SpringBoot09 自定义servlet、注册自定义的servlet、过滤器、监听器、拦截器、切面、webmvcconfigureradapter过时问题
1 servlet简介 servlet是一种用于开发动态web资源的技术 参考博客:servlet基础知识 httpservlet详解 2 在springboot应用中添加servlet sp ...