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 ...
随机推荐
- ios 各个手机型号尺寸及分辨率适配
常用宏 // 判断是否是ipad #define isPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdio ...
- windows任务计划定时备份sqlserver数据库
使用windows的任务计划新建一个sqlserver数据库的定时备份任务 一. (我是以sqlserver2008r2数据库版本测试的)在G盘下新建文集夹Database_backup,首 ...
- 构建企业级数据湖?Azure Data Lake Storage Gen2实战体验(中)
引言 相较传统的重量级OLAP数据仓库,“数据湖”以其数据体量大.综合成本低.支持非结构化数据.查询灵活多变等特点,受到越来越多企业的青睐,逐渐成为了现代数据平台的核心和架构范式. 因此数据湖相关服务 ...
- .NET分布式大规模计算利器-Orleans(一)
写在前面 Orleans是基于Actor模型思想的.NET领域的框架,它提供了一种直接而简单的方法来构建分布式大规模计算应用程序,而无需学习和应用复杂的并发或其他扩展模式.我在2015年下半年开始 ...
- PHPSTORM 2019 激活
1.获取激活码 请自行百度 2.输入激活码 3.配置本地hosts 添加配置如下 0.0.0.0 account.jetbrains.com 0.0.0.0 www.jetbrains.com
- .Net Core 添加 Swagger 支持
1. NuGet 中添加 Swashbuckle.AspNetCore 2.添加 Startup 信息 将 Swagger 生成器添加到 Startup.ConfigureServices 方法中的 ...
- Fliptile POJ-3279 DFS
题目链接:Fliptile 题目大意 有一个01矩阵,每一次翻转(0->1或者1->0)一个元素,就会把与他相邻的四个元素也一起翻转.求翻转哪些元素能用最少的步骤,把矩阵变成0矩阵. 思路 ...
- Hadoop点滴-何时使用hadoop fs、hadoop dfs与hdfs dfs命令
何时使用hadoop fs.hadoop dfs与hdfs dfs命令 编辑 删除 hadoop fs:使用面最广,可以操作任何文件系统. hadoop dfs与hdfs dfs:只能操作HDFS文件 ...
- js数组的增删改查
array 数组的增删改: push 从数组后面推入一个元素或多个元素 var arr = [1,2,3]; // 返回:修改后数组的长度 arr.push(4,5,6); pop 删除数组最后一 ...
- pyinstaller程序打包工具
PyInstaller是一个能将Python程序转换成单个可执行文件的程序, 操作系统支持Windows, Linux, Mac OS X, Solaris和AIX.并且很多包都支持开箱即用,不依赖环 ...