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

Description

— I just bought Leonardo's secret notebook! Rare object collector Stan Ucker was really agitated but his friend, special investigator Sarah Kepticwas unimpressed. 
— How do you know it is genuine? 
— Oh, it must be, at that price. And it is written in the da Vinci code. Sarah browsed a few of the pages. It was obvious to her that the code was a substitution cipher, where each letter of the alphabet had been substituted by another letter. 
— Leonardo would have written the plain-text and left it to his assistant to encrypt, she said. And he must have supplied the substitution alphabet to be used. If we are lucky, we can find it on the back cover! She turned up the last page and, lo and behold, there was a single line of all 26 letters of the alphabet: 
QWERTYUIOPASDFGHJKLZXCVBNM 
— This may be Leonardo's instructions meaning that each A in the plain-text was to be replaced by Q, each B withW, etcetera. Let us see... To their disappointment, they soon saw that this could not be the substitution that was used in the book. Suddenly, Stan brightened. 
— Maybe Leonardo really wrote the substitution alphabet on the last page, and by mistake his assistant coded that line as he had coded the rest of the book. So the line we have here is the result of applying some permutation TWICE to the ordinary alphabet! Sarah took out her laptop computer and coded fiercely for a few minutes. Then she turned to Stan with a sympathetic expression. 
— No, that couldn't be it. I am afraid that you have been duped again, my friend. In all probability, the book is a fake.

Write a program that takes a permutation of the English alphabet as input and decides if it may be the result of performing some permutation twice.

Input

The input begins with a positive number on a line of its own telling the number of test cases (at most 500). Then for each test case there is one line containing a permutation of the 26 capital letters of the English alphabet.

Output

For each test case, output one line containing Yes if the given permutation can result from applying some permutation twice on the original alphabet string ABC...XYZ, otherwise output No.

Sample Input

2
QWERTYUIOPASDFGHJKLZXCVBNM
ABCDEFGHIJKLMNOPQRSTUVWXYZ

Sample Output

No
Yes

Source

题意:

  给你一串大写的英文字母, 问你能不能通过2次置换ABCD···XYZ使得变成你要的字母串。

题解:

  如果存在一个置换 (a1, a2, a3)。那么 (a1, a2, a3)(a1, a2, a3) = (a1, a3, a2)。

  如果存在一个置换(b1, b2, b3, b4)。那么 (b1, b2, b3, b4)(b1, b2, b3, b4) = (b1, b3)(b2, b4)

  证明:

(a1, a2, a3)表示的是 a1 -> a2 , a2 -> a3 , a3 -> a1。

(需要学习置换的乘法)

当任意两个长度为n(奇数)的置换,都可以找到一个置换A , 满足A^2 = B。

当任意两个不相交的长度为n(奇数偶数都可以)循环置换 B, C ,都能找到一个长度为2n的循环置换A, 满足 A^2 = B C。

所以只要长度为偶数的置换有偶数个就可以输出Yes。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
using namespace std;
typedef long long LL;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
const int INF = 0x7fffffff;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+;
const int maxn = +;
void init(){ }
void solve() {
char B[];
int vis[], cnt[], T;
scanf("%d", &T);
while(T--){
scanf("%s", B);
ms(vis, );
ms(cnt, );
for(int i = ;i<;i++){
if(!vis[i]){
int j = i, n = ;
//cnt为长度
do{
vis[j] = ;
j = B[j] - 'A';
n++;
}while(j!=i);
cnt[n]++;
}
}
int ok = ;
for(int i = ;i<=;i+=)
if(cnt[i]%==)
ok = ;
if(ok) printf("Yes\n");
else printf("No\n");
}
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio();
cin.tie();
init();
solve();
return ;
}

POJ 3128 Leonardo's Notebook (置换)的更多相关文章

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

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

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

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

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

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

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

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

  5. UVaLive 3641 Leonardo's Notebook (置换)

    题意:给定一个置换 B 问是否则存在一个置换 A ,使用 A^2 = B. 析:可以自己画一画,假设 A = (a1, a2, a3)(b1, b2, b3, b4),那么 A^2 = (a1, a2 ...

  6. UVA12103 —— Leonardo's Notebook —— 置换分解

    题目链接:https://vjudge.net/problem/UVA-12103 题意: 给出大写字母“ABCD……Z”的一个置换B,问是否存在一个置换A,使得A^2 = B. 题解: 对于置换,有 ...

  7. [Poj3128]Leonardo's Notebook

    [Poj3128]Leonardo's Notebook 标签: 置换 题目链接 题意 给你一个置换\(B\),让你判断是否有一个置换\(A\)使得\(B=A^2\). 题解 置换可以写成循环的形式, ...

  8. LA 3641 (置换 循环的分解) Leonardo's Notebook

    给出一个26个大写字母的置换B,是否存在A2 = B 每个置换可以看做若干个循环的乘积.我们可以把这些循环看成中UVa 10294的项链, 循环中的数就相当于项链中的珠子. A2就相当于将项链旋转了两 ...

  9. Leonardo's Notebook UVALive - 3641(置换)

    题意: 给出26个大写字母的置换B,问是否存在一个置换A,使得A2 = B 解析: 两个长度为n的相同循环相乘,1.当n为奇数时结果也是一个长度为n的循环:2. 当n为偶数时分裂为两个长度为n/2 ( ...

随机推荐

  1. ubuntu18.04安装fcitx

    fcitx安装比较麻烦,我每次安装都要费不少劲,每次装安之后都没有写日志记录下来,导致下次装的时候又手忙脚乱,所以这次一定要记录下来. 前因: 我本来用的是ibus,但是这个输入法好像有bug,我在编 ...

  2. https和http的post发送总结

    本文为转贴内容,感谢作者阿进! 需要转发数据到客户的https的服务器上出现一系列问题总结如下: 1.因为是https首先考虑到用最新的控件NetHTTPClient(只有在XE8以上才有). 2.客 ...

  3. Delphi 图形图像对象组件

  4. Linux下源码编译安装MySql,centeros7

    1. 安cmake工具 # yum install -y cmake 2. 创建mysql用户  #useradd -s /sbin/nologin mysql  //设置为非登陆用户(安全) 3. ...

  5. 【2017-03-28】JS基础、windows对象、history对象、location对象

    一.JS基础 JS - javaScript 1.js功能: 1).进行数据的运算.2).控制浏览器的一些功能.3).控制元素(属性.内容.样式) js引用位置: 可以放在html页的任意位置. 推荐 ...

  6. windows下用navicat链接虚拟机MySQL数据库的过程和问题解决

    navicat远程连接虚拟机中的MySQL数据库 1.在linux查看mysql服务器IP地址 ifconfig 记住此IP navicat设置 设置完毕 遇到问题 一直连不上,在网上搜索了一下,主要 ...

  7. 使用Parallel计算目录中的文件字节长度

    /// <summary> /// 根据通配符和搜索条件计算给定目录中的文件字节长度 /// </summary> /// <param name="path& ...

  8. 小程序UI设计(10)-巧用模板,事半功倍

    工具中为小程序员们准备了符合微信开发规范的模板.之前帖子中介绍的规范都在模板中已经设计好了,可以直接复制粘贴使用.下图中的样式是从模板直接复制过来的.实际使用时只要更换为自己的图片和文字即可.自动生成 ...

  9. p2456二进制方程 题解

    题面描述:可以跳过 一个形如: X1X2…Xn=Y1Y2..Ym 的等式称为二进制方程. 在二进制方程的两边:Xi和Yj (1<=i<=n:1<=j<=m)是二进制数字(0.1 ...

  10. 第六章 组件 59 组件切换-使用Vue提供的component元素实现组件切换

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...