Main topic:
Give a a~z permutation g, ask if you can find a a~z permutation g ' can be used to represent g = g ' *g '
By the theorem:
Any one of the K-powers of a permutation of L, each of its cycles will be split into gcd (L, K), and each portion of the length is L/GCD (l,k)
This is the square of the permutation, so the circle section with an even length of G ' is bound to split into two equal cycle sections, an odd-numbered loop section, or a cyclic section length unchanged.
Then the resulting g in the length of the even-numbered loop section must be divided by the G ' in the even number of the cyclic section of the division, the odd loop can not be considered more, it is considered that it is the original odd-numbered circular section remains unchanged derived
So just make sure that the number of even-numbered loops in G can do 22 pairs.
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 6 intcnt[ -], to[ -], vis[ -];7 Charstr[ -];8 9 voidSolveintu)Ten { One intAns =1, V =u; A while(U! =To[v]) { -VIS[V] =1; -ans++; thev =To[v]; - } -VIS[V] =1; -cnt[ans]++; + } - + intMain () A { at //freopen ("a.in", "R", stdin); - intT; -scanf"%d", &T); - while(t--) - { -scanf"%s", str); in //establish a mapping relationship - for(intI=0; i< -; i++){ toto[i+1] = str[i]-'A'+1; + } -memset (CNT,0,sizeof(CNT)); thememset (Vis,0,sizeof(Vis)); * for(intI=1; i<= -; i++){ $ if(!vis[i]) solve (i);Panax Notoginseng } - intFlag =1; the //if any one of the circular sections is not paired with even numbers, output no + for(intI=1; i<= -; i++){ A if(Cnt[i] &&! (i&1)){ the if(cnt[i]&1){ +Flag =0; - Break; $ } $ - } - } the if(flag) printf ("yes\n"); - Elseprintf"no\n");Wuyi } the return 0; -}
Hrbust OJ 1536 Leonardo ' s Notebook permutation group problem