zoukankan      html  css  js  c++  java
  • POJ3128 Leonardo's Notebook 置换群分数幂

      题目链接:http://poj.org/problem?id=3128

      题意:给定一个置换,求是否能由另一个置换平方后组成。

      简单的性质,只要所给的置换中相等的偶数长度循环个数为偶数个就是可行解。

     1 //STATUS:C++_AC_0MS_196KB
     2 #include<stdio.h>
     3 #include<stdlib.h>
     4 #include<string.h>
     5 #include<math.h>
     6 #include<iostream>
     7 #include<string>
     8 #include<algorithm>
     9 #include<vector>
    10 #include<queue>
    11 #include<stack>
    12 #include<map>
    13 using namespace std;
    14 #define LL __int64
    15 #define pii pair<int,int>
    16 #define Max(a,b) ((a)>(b)?(a):(b))
    17 #define Min(a,b) ((a)<(b)?(a):(b))
    18 #define mem(a,b) memset(a,b,sizeof(a))
    19 #define lson l,mid,rt<<1
    20 #define rson mid+1,r,rt<<1|1
    21 const int N=30,INF=0x3f3f3f3f,MOD=10000,STA=8000010;
    22 const LL LNF=0x3f3f3f3f3f3f3f3f;
    23 const double DNF=1e13;
    24 
    25 char s[N],vis[N];
    26 int T;
    27 
    28 int main()
    29 {
    30  //   freopen("in.txt","r",stdin);
    31     int i,j,u,cnt[N],ok;
    32     scanf("%d",&T);
    33     while(T--)
    34     {
    35         mem(vis,0);
    36         mem(cnt,0);
    37         scanf("%s",s);
    38         for(i=0;i<26;i++)s[i]-='A';
    39         for(i=0;i<26;i++){
    40             if(!vis[i]){
    41                 u=i;j=0;
    42                 while(!vis[u]){
    43                     vis[u]=1;
    44                     j++;
    45                     u=s[u];
    46                 }
    47                 if(!(j&1))cnt[j]++;
    48             }
    49         }
    50         for(i=0,ok=1;i<N;i++)
    51             if(cnt[i]&1){ok=0;break;}
    52 
    53         printf("%s\n",ok?"Yes":"No");
    54     }
    55     return 0;
    56 }
  • 相关阅读:
    423. Reconstruct Original Digits from English
    400. Nth Digit
    397. Integer Replacement
    396. Rotate Function
    365. Water and Jug Problem
    335. Self Crossing
    319. Bulb Switcher
    线段树-hdu2795 Billboard(贴海报)
    线段树---求逆序数
    线段树——单点替换区间最值
  • 原文地址:https://www.cnblogs.com/zhsl/p/3019144.html
Copyright © 2011-2022 走看看