传送门:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3255
题解:LRJ训练之南p147
说一下碎玉置换A=(a1 a2 a3)(b1 b2 b3 b4)的平方怎么得出来的:
(a1 a2 a3)(a1 a2 a3)=>a1->a2->a3,a2->a3->a1,a3->a1->a2=(a1 a3 a2)
(b1 b2 b3 b4)(b1 b2 b3 b4)=> b1->b2->b3,b2->b3->b4,b3->b4->b1,b4->b1->b2=(b1 b3)(b2 b4)
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char s[30];
int vis[30],a[30];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s",s);
memset(vis,0,sizeof(vis));
memset(a,0,sizeof(a));
for(int i=0;i<26;i++)
{
if(!vis[i])
{
int j=i,n=0;
do{
vis[j]=1;
j=s[j]-'A';
n++;
}while(j!=i);
a[n]++;
}
}
int ok=1;
for(int i=2;i<=26;i+=2)
if(a[i]%2==1)ok=0;
if(!ok)printf("No\n");
else printf("Yes\n");
}
return 0;
}