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 ...
随机推荐
- Dubbo 与 Spring Cloud 完美结合
Dubbo 与 Spring Cloud 完美结合 1. 概述 可能说起来Dubbo,很多人都不陌生,这毕竟是一款从2012年就开始开源的Java RPC框架,中间由于各种各样的原因停止更新4年半的时 ...
- 判断是手机端还是PC短访问
第一种:判断是手机访问还是PC访问 <script> function browserRedirect() { var sUserAgent = navigator.userAgent.t ...
- CSS——字体
1.字体样式font-family.颜色color <!DOCTYPE html> <html> <head> <meta charset="UTF ...
- 《Java并发编程的艺术》读书笔记
一.并发编程的挑战 上下文切换:cpu通过时间片分配算法来循环执行任务,当前任务执行一个时间片后会切换到下一个任务.但是,在切换前会保存上一个任务的状态,以便下次切换回这个任务时,可以再加载这个任务的 ...
- [Leetcode] 第357题 计算各个位数不同的数字个数
一.题目描述 给定一个非负整数 n,计算各位数字都不同的数字 x 的个数,其中 0 ≤ x < 10n . 示例: 输入: 2 输出: 91 解释: 答案应为除去 11,22,33,44,55, ...
- 3D 飞行器航迹规划
3D-Route-Planning 三维航迹规划 -Matlab 本次代码主要解决数学建模中多约束条件下的航迹规划问题 解决的问题如下: 复杂环境下航迹快速规划是智能飞行器控制的一个重要课题.由于 ...
- WinServer 2012 R2 安装python3.6时出现错误:0x80240017 导致安装失败
解决方法: 依次检查并更新补丁:KB2919442,KB2919355,kb2999226 KB2919442:https://www.microsoft.com/zh-cn/download/det ...
- plsql导入导出表结构和数据对象
一.Tools的导出表结构:export User objects 二.Tools的Export Tables选项 导出表数据:export tables (选择:exp.exe) 三. 导入表结构: ...
- 07-简单认识margin
margin 外边距,表示边框到最近盒子的距离. 对于左右两边 <!DOCTYPE html> <html lang="en"> <head> ...
- http转换为https
1.下载ssl 证数 百度ssl 证数都有 其中以便宜ssl为例子 注册登陆 选择免费版 可以使用3个月: 申请过程中需要检测该域名是否为本人所有 ,所以邮箱检测或者域名配置 很简单检测就好了: 验证 ...