【HDU】4985 Little Pony and Permutation 置换群
来源:互联网 发布:制作书签的软件 编辑:程序博客网 时间:2024/05/09 04:15
传送门:【HDU】4985 Little Pony and Permutation
题目分析:基本置换群。内部排序反而错!
代码如下:
#include <cmath>#include <cstdio>#include <cstring>#include <algorithm>using namespace std ;#define REP( i , a , b ) for ( int i = ( a ) ; i < ( b ) ; ++ i )#define FOR( i , a , b ) for ( int i = ( a ) ; i <= ( b ) ; ++ i )#define REV( i , a , b ) for ( int i = ( a ) ; i >= ( b ) ; -- i )#define CLR( a , x ) memset ( a , x , sizeof a )const int MAXN = 100005 ;int a[MAXN] ;bool vis[MAXN] ;int S[MAXN] , top ;int n ;void scanf ( int& x , char c = 0 ) {while ( ( c = getchar () ) < '0' || c > '9' ) ;x = c - '0' ;while ( ( c = getchar () ) >= '0' && c <= '9' ) x = x * 10 + c - '0' ;}void solve () {CLR ( vis , 0 ) ;FOR ( i , 1 , n ) scanf ( a[i] ) ;FOR ( i , 1 , n ) if ( !vis[i] ) {int now = i ;top = 0 ;while ( !vis[now] ) S[top ++] = now , vis[now] = 1 , now = a[now] ;printf ( "(" ) ;REP ( j , 0 , top - 1 ) printf ( "%d " , S[j] ) ;printf ( "%d)" , S[top - 1] ) ;}printf ( "\n" ) ;}int main () {while ( ~scanf ( "%d" , &n ) ) solve () ;return 0 ;}
0 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(模拟置换)
- HDOJ题目4985Little Pony and Permutation(置换群)
- hdu 4985 Little Pony and Permutation
- HDU 4985 Little Pony and Permutation
- 杭电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(水题)
- 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
- bestcoder Round-#7 1001 Little Pony and Permutation
- HDU4985&&bestcoder #7 1001 Little Pony and Permutation(水题)
- gas_station——leetcode
- 1023. 组个最小数 (20)
- Android的近场通信---NFC概要
- oracle 相同数据删除(只留一条)
- java的多线程开发
- 【HDU】4985 Little Pony and Permutation 置换群
- 如何电涌保护器可以帮助笔记本电脑
- xcode5 arc 开启和关闭 出现错误提示 ARC forbids Objective-C
- 如何创建您自己的MP3铃声
- Android近场通信---NFC基础(一)
- 宏发大厦范德萨方式的公司的为公司的个
- PC-LINT的使用(一)
- 爱学习的小帅之Android面试笔记一(持续更新中....)
- Emoji表情符号兼容方案(转)