LA 3641 - Leonardo's Notebook(置换群)

3641 - Leonardo's Notebook

— I just bought Leonardo’s secret notebook! Rare objectcollector Stan Ucker was really agitated but his friend,special investigator Sarah Keptic was unimpressed.

— How do you know it is genuine?

— Oh, it must be, at that price. And it is written inthe da Vinci code. Sarah browsed a few of the pages. Itwas obvious to her that the code was a substitution cipher,where each letter of the alphabet had been substituted byanother letter.

— Leonardo would have written the plain-text and leftit to his assistant to encrypt, she said. And he must havesupplied the substitution alphabet to be used. If we arelucky, we can find it on the back cover!

She turned up the last page and, lo and behold, therewas a single line of all 26 letters of the alphabet:

QW ERT Y UIOP ASDF GHJKLZXCV BNM

— This may be Leonardo’s instructions meaning that each A in the plain-text was to be replacedby Q, each B with W, etcetera. Let us see. . .To their disappointment, they soon saw that this could not be the substitution that was used in thebook. Suddenly, Stan brightened.

— Maybe Leonardo really wrote the substitution alphabet on the last page, and by mistake hisassistant coded that line as he had coded the rest of the book. So the line we have here is the result ofapplying some permutation TWICE to the ordinary alphabet!

Sarah took out her laptop computer and coded fiercely for a few minutes. Then she turned to Stanwith 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 maybe 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 most500). Then for each test case there is one line containing a permutation of the 26 capital letters of theEnglish alphabet.

Output

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

Sample Input

2

QWERTYUIOPASDFGHJKLZXCVBNM

ABCDEFGHIJKLMNOPQRSTUVWXYZ

Sample Output

No

Yes

//题意:

给出26个大写字母的置换B,问是否存在一个置换A,使得A^2=B。

//思路:

设A=(a1 a2 a3)(b1 b2 b3 b4).则:A^2=(a1 a2 a3)(b1 b2 b3 b4)(a1 a2 a3)(b1 b2 b3 b4).==>>(a1 a2 a3)(a1 a2 a3)(b1 b2 b3 b4)(b1 b2 b3 b4)

由置换乘法的结合律,前面两个循环的乘积和后面两个循环乘积可以分别算,计算的:

(a1 a2 a3)(a1 a2 a3)=(a1 a3 a2)

(b1 b2 b3 b4)(b1 b2 b3 b4)=(b1 b3)(b2 b4)

由上可以看出规律:两个长度为n的相同的循环相乘,当n为奇数时结果也是一个长度为n的循环;当n为偶数时分裂为两个长度为n/2的循环。

所以可以把题中给出的B分解为不相交的循环的乘积。长度n为奇数的循环既可能是两个长度为n的相同的循环乘出来的,也可能是两个长度为2n的循环分裂成的,但长度n为偶数的循环只能是两个长度为2n的循环分裂成的。所以对于任意偶数长度,循环的个数必须是偶数才能配对。

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define INF 0x3f3f3f3f
#define ll long long
#define N 30
using namespace std;
int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
char b[N];
int vis[N],cnt[N];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int i;
		scanf("%s",b);
		memset(vis,0,sizeof(vis));
		memset(cnt,0,sizeof(cnt));		
		for(i=0;i<26;i++)
		{
			if(!vis[i])
			{
				int j=i;
				int n=0;
				while(1)
				{
					vis[j]=1;
					j=b[j]-'A';
					n++;
					if(j==i)
						break;
				}
				cnt[n]++;
			}	
		}
		int flag=1;
		for(i=2;i<=26;i+=2)
			if(cnt[i]%2&1)
				flag=0;
		printf(flag?"Yes\n":"No\n");
	}
	return 0;
} 


 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的体育馆管理系统,源码+数据库+毕业论文+视频演示 现代经济快节奏发展以及不断完善升级的信息化技术,让传统数据信息的管理升级为软件存储,归纳,集中处理数据信息的管理方式。本体育馆管理系统就是在这样的大环境下诞生,其可以帮助管理者在短时间内处理完毕庞大的数据信息,使用这种软件工具可以帮助管理人员提高事务处理效率,达到事半功倍的效果。此体育馆管理系统利用当下成熟完善的SpringBoot框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的Mysql数据库进行程序开发。实现了用户在线选择试题并完成答题,在线查看考核分数。管理员管理收货地址管理、购物车管理、场地管理、场地订单管理、字典管理、赛事管理、赛事收藏管理、赛事评价管理、赛事订单管理、商品管理、商品收藏管理、商品评价管理、商品订单管理、用户管理、管理员管理等功能。体育馆管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 关键词:体育馆管理系统;SpringBoot框架;Mysql;自动化
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值