Advertisement
royalsflush

Referência para Leonardo's Notebook (LA 3641)

Jul 3rd, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <algorithm>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6. int perm[30];
  7. int cycle[30];
  8. int _42;
  9. bool mark[30];
  10.  
  11. int main() {
  12.     scanf("%d", &_42);
  13.  
  14.     while (_42--) {
  15.         char tmp[30];
  16.         scanf(" %s", tmp);
  17.  
  18.         memset(mark,false,sizeof(mark));
  19.         memset(cycle,0,sizeof(cycle));
  20.  
  21.         for (int i=0; i<26; i++)
  22.             perm[i]=tmp[i]-'A';
  23.  
  24.         for (int i=0; i<26; i++)
  25.             if (!mark[i]) {
  26.                 int cnt=0, pos=i;
  27.                
  28.                 while (!mark[pos]) {
  29.                     mark[pos]=true, cnt++;
  30.                     pos=perm[pos];
  31.                 }
  32.                 cycle[cnt]++;
  33.             }
  34.  
  35.         bool can=true;
  36.         for (int i=1; i<=26; i++)
  37.             if (i%2==0 && cycle[i]%2)
  38.                 can=false;
  39.  
  40.         printf("%s\n", can? "Yes":"No");
  41.     }
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement