离散数学都快还给老师了。。
对于一个置换群P,它的一阶等于他本身。
那么这里我们求P的二阶,应该是对P * P,P对P轮换。
$egin{pmatrix}1 & 2 & 3\ a1 & a2 & a3end{pmatrix} * egin{pmatrix}1 & 2 & 3\ b1 & b2 & b3end{pmatrix} =egin{pmatrix}1 & 2 & 3\ b(a1) & b(a2) & b(a3) end{pmatrix}$
注意三阶应该是P的二阶对P的一阶置换。一开始算的时候一直拿P的二阶对P的二阶置换结果陷入了循环中。。
性质:https://blog.csdn.net/qq_36102055/article/details/107726401
POJ-1721:
#include<iostream> #include<stdio.h> #include<queue> #include<algorithm> #include<math.h> #include<stack> #include<map> #include<limits.h> #include<vector> #include<string.h> #include<string> using namespace std; typedef long long LL; typedef pair<LL,int> pii; const int N = 1e3 + 5; const int M = 1e5 + 5; const LL Mod = 199999; #define pi acos(-1) #define INF 1e9 #define dbg(ax) cout << "now this num is " << ax << endl; namespace FASTIO{ inline LL read(){ LL x = 0,f = 1;char c = getchar(); while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();} return x*f; } void print(int x){ if(x < 0){x = -x;putchar('-');} if(x > 9) print(x/10); putchar(x%10+'0'); } } using namespace FASTIO; int n,s,a[N],pp[N],p[N]; bool solve() { for(int i = 1;i <= n;++i) { pp[i] = p[p[i]]; } for(int i = 1;i <= n;++i) p[i] = pp[i]; for(int i = 1;i <= n;++i) { if(p[i] != a[i]) return false; } return true; } void solve2() { for(int i = 1;i <= n;++i) pp[i] = p[p[i]]; for(int i = 1;i <= n;++i) p[i] = pp[i]; } int main() { while(cin >> n >> s) { for(int i = 1;i <= n;++i) a[i] = read(),p[i] = a[i]; int len = 0; while(1) { ++len; if(solve()) break; } int ch = len - s % len; for(int i = 1;i <= n;++i) p[i] = a[i]; while(ch--) solve2(); for(int i = 1;i <= n;++i) printf("%d ",p[i]); } system("pause"); return 0; }