【HDU】4985 Little Pony and Permutation 置换群
2014-09-04 15:40
405 查看
传送门:【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 ; }
相关文章推荐
- HDU 4985-Little Pony and Permutation(模拟置换)
- hdu 4985 Little Pony and Permutation(置换)
- HDU 4985 Little Pony and Permutation(置换)
- [BestCoder Round #7] hdu 4985 Little Pony and Permutation (找循环节)
- hdu 4985 Little Pony and Permutation
- 【CUGBACM15级BC第7场 A】hdu 4985 Little Pony and Permutation
- hdu 4985 Little Pony and Permutation(水题)
- 杭电4985 Little Pony and Permutation(水置换)
- HDU 4985 Little Pony and Permutation(数学 置换群)
- BestCoder7 1001 Little Pony and Permutation(hdu 4985) 解题报告
- HDU 4985 Little Pony and Permutation(简单模拟)
- 【HDOJ】4985 Little Pony and Permutation
- 【强连通分量】 HDOJ 4985 Little Pony and Permutation
- HDU 4987/BC 7C Little Pony and Dice
- BestCoder7 1002 Little Pony and Alohomora Part I(hdu 4986) 解题报告
- hdu 4986 Little Pony and Alohomora Part I(找规律,欧拉常数)
- HDU 4986 Little Pony and Alohomora Part I(递推+欧拉常数)
- bestcoder Round-#7 1001 Little Pony and Permutation
- hdu 4986 Little Pony and Alohomora Part I(递推)
- HDU 4986 Little Pony and Alohomora Part I(递推+犹拉常数)