Question: Link
Question: replace B with 26 uppercase letters and ask if there is a replace a, so that a ^ 2 = B
Train of Thought: To sum up a rule: two identical loops with N length are multiplied. When n is an odd number, the result is also a loop with N length; when N is an even number, it is split into two cycles with a length of n/2, therefore, for an odd number of cycles with a length of N, we can find a loop with a length of n so that a ^ 2 = B. For the two cycles with an length of N, we can find an even number) both B and C can find a loop a with a length of 2n so that a ^ 2 = BC. That is to say, we only need to ensure that the length is an even number and the number is an even number, as for a cyclic decomposition, we can construct a ring by following the directed edge.
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; int main () {char B [30]; int vis [30], CNT [30], T; scanf ("% d", & T); While (t --) {scanf ("% s", B ); memset (VIS, 0, sizeof (VIS); memset (CNT, 0, sizeof (CNT); For (INT I = 0; I <26; I ++) if (! Vis [I]) {Int J = I, n = 0; do {vis [J] = 1; j = B [J]-'A'; n ++ ;} while (J! = I); CNT [N] ++;} int flag = 1; for (INT I = 2; I <= 26; I + = 2) if (CNT [I] % 2 = 1) Flag = 0; If (FLAG) printf ("Yes \ n"); else printf ("NO \ n ");} return 0 ;}
Ultraviolet-12103 Leonardo's notebook