"LA 3641" Leonardo ' s Notebook (permutation group)

Source: Internet
Author: User

Test instructions

Give 26 uppercase letters a string B ask if there is a permutation a so a^2 = b

Analysis

The replacement has already been said, after doing this problem has a deeper understanding.

Besides, the permutation group.

The first is the group.

  

The element of permutation group is permutation, and the operation is the connection of permutation.

  It's been said before. , each permutation can be written as the product of a disjoint loop.

   

  Then analyze the problem.

Suppose a permutation is (A1,A2,A3) (B1,B2,B3,B4) "Here with a loop representation

Then A*a= (A1,A2,A3) (B1,B2,B3,B4) (A1,A2,A3) (B1,B2,B3,B4)

Non-intersecting loops satisfy the commutative law, so

A*a= (A1,A2,A3) (A1,A2,A3) (B1,B2,B3,B4) (B1,B2,B3,B4)

Satisfies the Binding Law a*a= ((A1,A2,A3) (A1,A2,A3)) * ((B1,B2,B3,B4) (B1,B2,B3,B4))

(A1,A2,A3) (A1,A2,A3) = (A1,A3,A2)

(B1,B2,B3,B4) (B1,B2,B3,B4) = (B1,B3) (B2,B4)

Analysis here can consider B, first divides the B into a number of disjoint loops, for the length of the n-odd cycle, he can be two-length of n-cycle multiplication, it may be two of the length of a 2n loop split into.

For a length of n-even cycles, he can only be divided into two loops of length 2n. So even loops must be 22 pairs equal in length.

That is, if there is an odd number of identical even loops, output no, or you can find a legitimate a.

1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <iostream>5#include <algorithm>6 using namespacestd;7 #defineMAXN 308 9 intA[MAXN],ANS[MAXN];Ten BOOLVIS[MAXN]; One  A CharS[MAXN]; -  - intMain () the { -     intT; -scanf"%d",&T); -      while(t--) +     { -scanf"%s", s); +          for(intI=0; i<= -; i++) a[i+1]=s[i]-'A'+1; Amemset (Vis,0,sizeof(Vis)); atmemset (ans,0,sizeof(ans)); -          for(intI=1; i<= -; i++)if(!Vis[i]) -         { -             intCnt=0, x=i; -              while(vis[x]==0) -             { incnt++; -vis[x]=1; tox=A[x]; +             } -ans[cnt]++; the         } *         BOOLok=1; $          for(intI=2; i<= -; i+=2)Panax Notoginseng         { -             if(ans[i]%2==1) ok=0; the         } +         if(OK) printf ("yes\n"); A         Elseprintf"no\n"); the     } +     return 0; -}
View Code

Good wit Oh, this is not very difficult to see.

The code is also simple:

2017-01-11 16:49:20

"LA 3641" Leonardo ' s Notebook (permutation group)

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.