置换的开方。

看看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. 低调、奢华、有内涵的敏捷式大数据方案:Flume+Cassandra+Presto+SpagoBI

    基于FacebookPresto+Cassandra的敏捷式大数据 文件夹 1 1.1 1.1.1 1.1.2 1.2 1.2.1 1.2.2 2 2.1 2.2 2.3 2.4 2.5 2.6 3 ...

  2. Caffe C++API 提取任意一张图片的特征系列二----MemoryData

    介绍一种更加灵活的方法,用MemoryData层输入数据,可以直接用opencv接口读入我们的图片再添加的网络中.  第一个问题:仍然是工程建立问题,提示卷积层或其他层没有注册,解决方法与上一篇博客一 ...

  3. 【NOI 2002】 银河英雄传说

    [题目链接] https://www.luogu.org/problemnew/show/P1196 [算法] 并查集 [代码] #include<bits/stdc++.h> using ...

  4. USACO 1.5 Superprime Rib

    Superprime Rib Butchering Farmer John's cows always yields the best prime rib. You can tell prime ri ...

  5. DB-MySQL:MySQL 索引

    ylbtech-DB-MySQL:MySQL 索引 1.返回顶部 1. MySQL 索引 MySQL索引的建立对于MySQL的高效运行是很重要的,索引可以大大提高MySQL的检索速度. 打个比方,如果 ...

  6. filezilla的root账户无法连接服务器解决办法

    lz一直都是用filezilla上传文件到vm虚拟机的,用的是ubuntu14.04的系统.最近自己重新搭了lamp去做thinkphp的学习,lz有两个账户,一个是kin,另外一个是root.大家都 ...

  7. Underscore模板的使用

    一.开篇 下载underscode.js 二.使用 <!DOCTYPE html> <html lang="en"> <head> <me ...

  8. COM基础

    为什么说COM的可重用性是建立在二进制级别? COM本身是语言无关,它的标准建立在二进制级别.对于使用COM组件的客户程序,它只需要要使用的COM对象信息就可以通过COM库的帮助创建和使用COM对象, ...

  9. [转自百度贴吧-本人亲测有效]Adobe XD 打开立即闪退问题修复

    出现闪退的原因还是因为缺少C++组件, 下载 DirectXRepairV3.7软件 原文: https://tieba.baidu.com/p/5961511474 软件下载: http://xia ...

  10. HDU1166 敌兵布阵 线段树详解

    题解: 更新是线段树的单点更新,简单一点. 有50000个阵营,40000查询,用普通数组肯定超时.区间求和和区间查询问题用线段树最好不过了. 先说说什么是线段树. 区间[1,10]用树的方法存起来, ...