Codeforces 986B - Petr and Permutations
Description\text{Description}Description
Given an array a[], swap random 2 number of them for 3n or (7n+1) times.\text{Given an array }a[],\text{ swap random 2 number of them for }3n\text{ or }(7n+1)\text{ times.}Given an array a[], swap random 2 number of them for 3n or (7n+1) times.
Please compute how many times for swaping.\text{Please compute how many times for swaping.}Please compute how many times for swaping.
Solution\text{Solution}Solution
It’s easy to know that if we keep swaping a[i] and a[a[i]], they’ll always\text{It's easy to know that if we keep swaping }a[i]\text{ and }a[a[i]],\text{ they'll always}It’s easy to know that if we keep swaping a[i] and a[a[i]], they’ll always
goes a[i]=i at last.\text{goes }a[i]=i\text{ at last.}goes a[i]=i at last.
Counting times we’ve done that so that ∀i,a[i]=i. Check its parity.\text{Counting times we've done that so that }\forall i,a[i]=i.\text{ Check its parity.}Counting times we’ve done that so that ∀i,a[i]=i. Check its parity.
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
int n;
int a[1000010];
int ans=0;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i)
scanf("%d",&a[i]);
for(int i=1;i<=n;++i)
while(a[i]!=i){
std::swap(a[i],a[a[i]]);
++ans;
}
if(ans%2==n%2) puts("Petr");
else puts("Um_nik");
}
Codeforces 986B - Petr and Permutations的更多相关文章
- Codeforces 986B. Petr and Permutations(没想到这道2250分的题这么简单,早知道就先做了)
这题真的只能靠直觉了,我没法给出详细证明. 解题思路: 1.交换3n次或者7n+1次,一定会出现一个为奇数,另一个为偶数. 2.用最朴素的方法,将n个数字归位,计算交换次数. 3.判断交换次数是否与3 ...
- Codeforces 987E Petr and Permutations(数组的置换与复原 、结论)
题目连接: Petr and Permutations 题意:给出一个1到n的序列,Petr打乱了3n次,Um_nik打乱了7n+1次,现在给出被打乱后的序列,求是谁打乱的. 题解:因为给出了一个3* ...
- 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 ...
- CF986B Petr and Permutations [逆序对]
题目传送门 Petr and Permutations 格式难调,题面就不放了. 分析: 胡乱分析+猜测SP性质一波.然后被学长告知:“1~n的排列交换次数与逆序对的奇偶性相同.”然后就愉快地A了. ...
- 【Codeforces 986B】Petr and Permutations
[链接] 我是链接,点我呀:) [题意] 题意 [题解] n为奇数时3n和7n+1奇偶性不同 n为偶数时也是如此 然后交换任意一对数 逆序对的对数的奇偶性会发生改变一次 求出逆序对 对n讨论得出答案. ...
- Petr and Permutations CodeForces - 987E(逆序对)
题意: 给出一个长度为n的序列,求出是谁操作的(原序列为从小到大的序列),Peter的操作次数为3n,Alex的操作次数为7n+1 解析: 我们来看这个序列中的逆序对,逆序对的个数为偶数则操作次数为偶 ...
- Codeforces Round #337 Alphabet Permutations
E. Alphabet Permutations time limit per test: 1 second memory limit per test: 512 megabytes input: ...
- codeforces 341C Iahub and Permutations(组合数dp)
C. Iahub and Permutations time limit per test 1 second memory limit per test 256 megabytes input sta ...
随机推荐
- Java线程常见面试题
v 多线程实现手段: (1).继承Thread类 (2)实现Runable接口 (3)使用线程池 v 线程控制在那个包:java.util.concurrent. (1)提供了线程的运行.(2)线程池 ...
- asp.net 导出excel带图片
protected void btgua_Click(object sender, EventArgs e) { DataTable dt = ds.Tables[0]; if (dt != null ...
- Elasticsearch(9) --- 聚合查询(Bucket聚合)
Elasticsearch(9) --- 聚合查询(Bucket聚合) 上一篇讲了Elasticsearch聚合查询中的Metric聚合:Elasticsearch(8) --- 聚合查询(Metri ...
- Channel使用技巧
前言 Go协程一般使用channel(通道)通信从而协调/同步他们的工作.合理利用Go协程和channel能帮助我们大大提高程序的性能.本文将介绍一些使用channel的场景及技巧 场景一,使用cha ...
- hadoop之mapreduce详解(基础篇)
本篇文章主要从mapreduce运行作业的过程,shuffle,以及mapreduce作业失败的容错几个方面进行详解. 一.mapreduce作业运行过程 1.1.mapreduce介绍 MapRed ...
- redis 主从复制和哨兵模式(二)
Redis 主从复制 为了分担单机 redis 的数据服务压力,需要进行读写分离,所以搭建 redis 的主从结构,主节点负责写,从节点负责读,主节点定期把数据同步到从节点. 配置主从 # 配置文件中 ...
- 推荐几个我近期排查线上http接口偶发415时用到的工具
导读:近期有一个业务部门的同学反馈说他负责的C工程在小概率情况下SpringMvc会返回415,通过输出的日志可以确定是SpringMvc找不到content-type这个头了,具体为什么找不到了呢? ...
- Windows和Linux下scrapy框架的安装
windows下安装: 1.安装Anaconda环境管理工具 也可以使用pip安装,值得注意的是如果你使用的是pip安装,你需要解决相应的包依赖(解决依赖一般会让你怀疑人生.怀疑scrapy,建议还是 ...
- .Net Core自动化部署系列(一):Jenkins + GitLab
项目进行微服化改造后系统发布就变得愈为重要,因为持续集成导致部署变得越来越频繁,人工部署带来的一些问题日渐凸显,大家可能都有被系统部署线问题困扰过的经历. 本篇我们将会使用Jenkins+Gitlab ...
- Scala 学习笔记之集合(9) 集合常用操作汇总
object CollectionDemo10 { def main(args: Array[String]): Unit = { var ls = List[Int](1, 2, 3) //向后增加 ...