置换的开方。

看看Pan的那篇集训论文。此处,可以想到,开方时,由于gcd(l,2),则必然有若是循环长度为偶数,必定是成对出现的。若是奇数,既可以是偶数也可以是奇数,因为,通过二次方后,循环长度为偶数的可以分裂成偶数的两个也可以是奇数的两个。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring> using namespace std; char str[30];
bool vis[30];
int cnt[30]; bool confirm(){
bool flag=true;
for(int i=1;i<=26;i++)
if(i%2==0){
if(cnt[i]%2){
flag=false;
break;
}
}
return flag;
} int main(){
int T,cnted;
scanf("%d",&T);
while(T--){
scanf("%s",str);
memset(vis,false,sizeof(vis));
memset(cnt,0,sizeof(cnt));
for(int i=0;i<26;i++){
if(!vis[i]){
int k=i;
cnted=0;
while(!vis[k]){
vis[k]=true;
k=str[k]-'A';
cnted++;
}
cnt[cnted]++;
}
}
if(confirm())
printf("Yes\n");
else printf("No\n");
}
return 0;
}

  

POJ 3128的更多相关文章

  1. poj 3128 Leonardo&#39;s Notebook(置换的幂)

    http://poj.org/problem?id=3128 大致题意:输入一串含26个大写字母的字符串,能够把它看做一个置换.推断这个置换是否是某个置换的平方. 思路:具体解释可參考url=ihxG ...

  2. poj 3128 Leonardo's Notebook——思路(置换)

    题目:http://poj.org/problem?id=3128 从环的角度考虑. 原来有奇数个点的环,现在点数不变: 原来有偶数个点的环(设有 k 个点),现在变成两个大小为 k/2 的环. 所以 ...

  3. poj 3128 Leonardo's Notebook (置换群的整幂运算)

    题意:给你一个置换P,问是否存在一个置换M,使M^2=P 思路:资料参考 <置换群快速幂运算研究与探讨> https://wenku.baidu.com/view/0bff6b1c6bd9 ...

  4. POJ 3128 Leonardo's Notebook [置换群]

    传送门 题意:26个大写字母的置换$B$,是否存在置换$A$满足$A^2=B$ $A^2$,就是在循环中一下子走两步 容易发现,长度$n$为奇数的循环走两步还是$n$次回到原点 $n$为偶数的话是$\ ...

  5. POJ 3128 Leonardo's Notebook (置换)

    Leonardo's Notebook Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2324   Accepted: 98 ...

  6. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  7. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  8. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  9. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

随机推荐

  1. SwipeRefreshLayout与ViewPager滑动事件冲突解决

    问题描写叙述: 开发中发现,SwipeRefreshLayout的下拉刷新,与ViewPager开发的banner的左右滑动事件有一点冲突,导致banner的左右滑动不够顺畅. 非常easy在bann ...

  2. 通过Gulp流方式处理流程

    http://www.cnblogs.com/gongcheng9990/archive/2014/11/25/4120434.html http://modernweb.com/2014/08/04 ...

  3. DNS隧道之DNS2TCP实现——dns2tcpc必须带server IP才可以,此外ssh可以穿过墙的,设置代理上网

    我自己的命令: server端: dns2tcpd -F -d 1 -f ./dns2tcpd.conf 输出: 09:08:59 : Debug options.c:97 Add resource ...

  4. Vue读书笔记:关于$ref、props和$emit

    1.props实现父组件向子组件传递数据 子组件可以通过props接收到来自父组件的数据,并且是单向绑定的.也就是说,数据不能从子组件反向传递. 2.$ref实现子组件向父组件通信 来自官方非常难理解 ...

  5. 11.QT窗口布局切割

    int main(int argc, char *argv[]) { QApplication a(argc, argv); //MainWindow w; //w.show(); //左右分割 7 ...

  6. Noip前紧急抢救

    管他会不会,知道结论就好了 紧急抢救知识 斯特林数 第一类斯特林数 递推公式 \[ S[n][k]=(n-1)\times S[n-1][k]+S[n-1][k-1] \] 处理的问题是将n个数划分为 ...

  7. caffe下python环境的编译

    安装python所需的依赖包 (1)sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-n ...

  8. SQL Server 分割字符串转列

    CREATE FUNCTION dbo.sf_DS_SplitNVarchar ( @strValues nvarchar(4000) ) RETURNS @tblStrList TABLE (id ...

  9. SQL常用函数集锦

    ..STUFF()用另一子串替换字符串指定位置.长度的子串.STUFF (<character_expression1>, <start_ position>, <len ...

  10. DB2load遇到SQL3508N错误

    SQL3508N装入或装入查询期间,当存取类型为 "<文件类型>" 的文件或路径时出错.原因码:"<原因码>".路径:"< ...