# POJ 1271 CARDS 置换/循环节/置换群开方

[问题描述]

[输入]

[输出]

[算法分析]

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define MAXN 1100
int p[MAXN];
bool flag[MAXN];

void permute ( int n ) //模拟置换
{
int now, i, tmp[MAXN];
memset(flag,0,sizeof(flag));
for ( i = 1; i <= n; i++ )
{
if ( flag[i] ) continue;
now = i;
while ( flag[now] == 0 )
{
flag[now] = 1;
tmp[now] = p[p[now]];
now = p[p[now]];
}
}
for ( i = 1; i <= n; i++ ) p[i] = tmp[i];
}

int mod_exp ( int a, int b, int n )
{
int ret = 1;
a = a % n;
while ( b >= 1 )
{
if ( b & 1 )
ret = ret * a % n;
a = a * a % n;
b >>= 1;
}
return ret;
}

int main()
{
int n, s, a, i;
scanf("%d%d",&n,&s);
for ( i = 1; i <= n; i++ )
scanf("%d",&p[i]);
for ( a = 1; mod_exp(2,a,n) != 1; a++ );
s = s % a;
for ( i = 1; i <= a - s; i++ )
permute ( n );
for ( i = 1; i <= n; i++ )
printf("%d\n",p[i]);
return 0;
}


#### [ACM] poj 2369 Permutations (置换群循环节长度）

2014-03-31 20:05:34

#### 【poj 3128】置换群 循环节

2014-08-10 15:28:01

#### 【证明】关于项链问题中旋转操作的置换群的循环节个数、长度的证明【Pólya】【同余】

2016-02-15 17:09:16

#### ACM_置换群 burnside引理 Polya定理

2016-06-27 14:06:01

#### 置换群题目汇总

2015-04-21 16:28:29

#### 置换群小结

2016-01-27 15:22:07

#### 置换 置换群 应用 +置换群对某些算法问题的解释

2012-09-20 21:29:15

#### 置换群的幂运算总结

2016-12-05 20:38:35

#### 置换群的基本概念与题目

2017-08-07 23:35:14

#### 置换群Polya定理

2014-07-30 17:24:15