cf 153.div2 D. Playing with Permutations
来源:互联网 发布:五笔 知乎 编辑:程序博客网 时间:2024/05/18 00:49
D. Playing with Permutations
比赛的时候一直没看懂题,后来看了下,其实很简单,就是给你一个变换序列q ,有两种变换1和2,1就是令Pi=Pqi,2则相反,互为逆变换,所以只要单独求出每种变换要多少少次,即可判断出来能否成功变换。
/*author:jxylang:C/C++university:China,Xidian University**If you need to reprint,please indicate the source***/#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <queue>#include <map>#define INF 1E9using namespace std;int q[100];string aim="";char p[105];int i,n;string c1(string s){ for(i=0;i<n;i++) p[i]=s[q[i]]; return p;}string c2(string s){ for(i=0;i<n;i++) p[q[i]]=s[i]; return p;}string now="",nn;int k1,k2;int main(){ int k,t,lvl; scanf("%d%d",&n,&k); for(i=0;i<n;i++) { scanf("%d",&q[i]); q[i]--; } for(i=0;i<n;i++) { scanf("%d",&t); aim.push_back(t); now.push_back(i+1); } nn=now; for(k1=0;k1<=k&&now!=aim;now=c1(now),k1++); for(k2=0;k2<=k&&nn!=aim;nn=c2(nn),k2++); if((k-k2)%2&&(k-k1)%2||(k>1&&k1==1&&k2==1)||!k1)cout<<"NO"<<endl; else cout<<"YES"<<endl;}
- cf 153.div2 D. Playing with Permutations
- cf 251 B Playing with Permutations 暴力 分类讨论
- cf 154.div2 D. Table with Letters - 2
- CF 174(div2) D
- CF 161 div2 D
- CF 189 div2 D
- CF 159 div2 d
- cf.256.div2.D
- cf R327 div2 D
- codeforces 251B Playing with Permutations 模拟
- D-codeforces527A- Playing with Paper
- CF 190div2 D(贪心)
- CF 345 div2 D题
- cf div2 #453 ABC(D)
- CF 463D Gargari and Permutations (dp)
- CF 463D Gargari and Permutations [dp]
- CF round #79 div2 D bues
- CF #109 div2 D题 Colliders
- hibernate使用注解时的工具类
- asp.net gridview通用类
- cf 153.div2 B. Unsorting Array
- 324的成绩单出来啦。。。。
- zoj2334-Monkey King(超时)
- cf 153.div2 D. Playing with Permutations
- 安装最新的文泉驿字体[z]
- Python切片索引
- 黑马程序员_java反射机制的学习笔记
- cf 154.div2 D. Table with Letters - 2
- vim配置
- vim tab设置
- [iOS]retain\assign\copy的区别
- Invalid action class configuration that references an unknown class named[XXXAction]