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 ...
随机推荐
- SpringMVC---依赖注入与面向切面
1.依赖注入与面向切面 1.1.出现背景 ——如何简化java开发? 其中很重要的一点是“组件化”. ——如何更好的“组件化”? 松耦合,以及尽可能的让组件专注于本身. ——Spring框架的目的也只 ...
- c#的日志插件NLog基本使用
本文介绍c#的日志插件NLog 安装插件 创建logger 日志级别 书写日志信息 配置 包装器 布局 安装插件 直接下载插件包 Install-Package NLog.Config 创建logge ...
- Shell编程进阶 1.3data命令
date命令是显示日期时间的命令 date 2016年 01月 01日 星期五 15:05:01 CST 修改时间的选项是 -s date -s "2016-01-01 12:56:10&q ...
- HTML元素(包括HTML5)的标签、属性及事件大全
1.标签列表 标签 描述 <!–…–> 定义注释. <!DOCTYPE> 定义文档类型. <a> 定义超链接. <abbr> 定义缩写. <acr ...
- DAY3-python函数
目录 一.了解函数 二. 函数定义 三.函数使用原则:先定义,后调用 四.定义函数的三种形式 五.函数的调用 六.函数的参数 七. 函数对象 八.函数嵌套 九.名称空间与作用域 十. 闭包函数 十一. ...
- B和strong以及i和em的区别(转)
B和strong以及i和em的区别 (2013-12-31 13:58:35) 标签: b strong i em 搜索引擎 分类: 网页制作 一直以来都以为B和strong以及i和em是相同的效果, ...
- php学习笔记-默认参数
在定义函数的时候,我们可以把其中的一个参数变的特殊起来,使它有一个默认值,这个参数就叫默认参数.在调用这个函数的时候,你既可以给这个默认参数传递一个值,这样的话默认参数的值会被覆盖掉,也可以不给它传递 ...
- 1003 NOIP 模拟赛Day2 城市建设
题面不好找放一个吧. Description 描述 在有$N$个地级市的H省,政府为了城市开发建设,决定先修路,后造房子,以吸引外来人员.一开始每个城市中有$b_i$个住户,而在两个城市$u,v$之间 ...
- Django框架 之 ORM 常用字段和参数
Django框架 之 ORM 常用字段和参数 浏览目录 常用字段 字段合集 自定义字段 字段参数 DateField和DateTimeField 关系字段 ForeignKey OneToOneFie ...
- js获取指定小时日期格式化
不得不感叹一下,聪明的程序员写的代码真是让人惊奇 找了一圈格式化代码的方式,下面的这个使用了一个 slice 函数,真是厉害 https://stackoverflow.com/questions/4 ...