HDU 4985 Little Pony and Permutation
来源:互联网 发布:a href js 函数 编辑:程序博客网 时间:2024/05/24 15:40
水题~
注意:不是按照字典序进行排列输出,只要保证从“1”开始遍历就可以了
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int cnt[100100];int a[100100];int b[100100];int c[100100];int main(){ int n; while(~scanf("%d",&n)) { memset(cnt,0,sizeof(cnt)); for(int i=1; i<=n; i++) { scanf("%d",&a[i]); } int nn=0; if(n==1) { if(a[1]==1) printf("(1)\n"); else printf("(1 %d)\n",a[1]); continue; } for(int i=1; i<=n; i++) { int num=0; int k=a[i]; if(cnt[k]==0) { cnt[i]=1; b[num]=i; num++; while(1) { if(cnt[k]!=0) break; b[num]=k; num++; nn++; cnt[k]=1; k=a[k]; } printf("("); for(int i=0; i<num-1; i++) printf("%d ",b[i]); printf("%d)",b[num-1]); } if(nn==n) break; } printf("\n"); } return 0;}
1 0
- hdu 4985 Little Pony and Permutation
- hdu 4985 Little Pony and Permutation(置换)
- HDU 4985 Little Pony and Permutation(置换)
- HDU 4985 Little Pony and Permutation
- 【HDU】4985 Little Pony and Permutation 置换群
- HDU 4985 Little Pony and Permutation(数学 置换群)
- HDU 4985 Little Pony and Permutation(简单模拟)
- HDU 4985/BC 7A Little Pony and Permutation
- hdu 4985 Little Pony and Permutation(水题)
- HDU 4985-Little Pony and Permutation(模拟置换)
- bc7 Little Pony and Permutation
- [BestCoder Round #7] hdu 4985 Little Pony and Permutation (找循环节)
- 【CUGBACM15级BC第7场 A】hdu 4985 Little Pony and Permutation
- 【强连通分量】 HDOJ 4985 Little Pony and Permutation
- HDOJ题目4985Little Pony and Permutation(置换群)
- 杭电4985 Little Pony and Permutation(水置换)
- bestcoder Round-#7 1001 Little Pony and Permutation
- HDU4985&&bestcoder #7 1001 Little Pony and Permutation(水题)
- 蛇形填数
- csdn待改进点之32------>是谁去掉/删除了我博客的一条正常评论?
- CSP考试 2015年03月第4题 网络延时 C语言实现
- 仿QQ阅读UI布局的搭建之感想
- ArrayAdapter学习
- HDU 4985 Little Pony and Permutation
- git的简单使用
- 走迷宫
- 深入理解JavaScript类数组
- JAVA环境变量配置
- 【MyBatis框架】mapper配置文件-foreach标签
- Economy Game
- java关键字static
- Android第5天,httpclient,多线程断点续传,进度条,xUtils