Test Instructions:Link
Method:Permutation group
parsing:Quite a simple permutation group? But the first time was too two to think wrong. I thought I was going to just follow that sequence and get the power of the permutation group OK. The results found that I did not affect this many loops-it is not funny. So hurry back and ask for a loop. For each of the intra-cycle permutations, the water problem is followed.
Code:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define Nusing namespace STD;intN,k;intA[n];intB[n][n];intV[n];CharTmp[n];CharPrint[n];intTotintLenth;voidGetn () {memset(V,0,sizeof(v)); for(intI=1; i<=n;i++) {intpt=i;if(!v[pt]) tot++;intCnt=0; while(!v[pt]) {v[pt]=1; B[TOT][++CNT]=A[PT]; PT=A[PT]; }if(cnt!=0) b[tot][0]=cnt; }}intMain () { while(~scanf("%d", &n)) {if(n==0) Break; for(intI=1; i<=n;i++)scanf("%d", &a[i]); tot=0; GETN (); while(~scanf("%d", &k)) {if(k==0){printf("\ n"); Break;}Charuseless;scanf("%c", &useless); Gets (TMP);intlen=strlen(TMP); while(len<n) tmp[len++]="'; tmp[len]=' + '; for(intI=1; i<=tot;i++) { for(intj=1; j<=b[i][0];j++) {intTmp2= (j+k)%b[i][0];if(!TMP2) tmp2=b[i][0]; print[b[i][tmp2]-1]=tmp[b[i][j]-1]; } } for(intI=0; i<n;i++) {printf("%c", Print[i]); }printf("\ n"); } }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ 1026 Cipher Permutation Group