Hrbust OJ 1536 Leonardo ' s Notebook permutation group problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.