UVaLive 3641 Leonardo's Notebook (置换)
题意:给定一个置换 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),不相关循环可以有交换律。
A^2 = (a1, a2, a3)(a1, a2, a3)(b1, b2, b3, b4)(b1, b2, b3, b4),分别考虑这两个循环,可以得到两个奇循环置换后仍然是一个奇循环,而两个偶循环置换后就是两个 n/2 循环,n 是 循环的长度,所以对于这个题目,B 中的所有奇循环,都可以从 A 得到,而偶循环,必须两两配对,才能存在,配对指的是长度一样。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
//#define all 1,n,1
#define FOR(i,n,x) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.in", "r", stdin)
#define freopenw freopen("out.out", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 30 + 10;
const int maxm = 1e6 + 2;
const LL mod = 1000000007;
const int dr[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dc[] = {0, 0, 1, -1, 1, -1, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} char s[maxn];
bool vis[maxn]; int main(){
int T; cin >> T; n = 26;
while(T--){
scanf("%s", s); ms(vis, 0);
vector<int> v;
for(int i = 0; i < n; ++i) if(!vis[i]){
int cnt = 1, x = i;
while(s[x] != i + 'A'){
++cnt; x = s[x] - 'A';
vis[x] = 1;
}
v.pb(cnt);
}
sort(v.begin(), v.end()); v.pb(-1);
bool ok = true;
for(int i = 0; i < v.sz && ok; ++i)
if(v[i] % 2 == 0){
if(v[i] != v[i+1]) ok = false;
else ++i;
}
puts(ok ? "Yes" : "No");
}
return 0;
}
UVaLive 3641 Leonardo's Notebook (置换)的更多相关文章
- UVA12103 —— Leonardo's Notebook —— 置换分解
题目链接:https://vjudge.net/problem/UVA-12103 题意: 给出大写字母“ABCD……Z”的一个置换B,问是否存在一个置换A,使得A^2 = B. 题解: 对于置换,有 ...
- POJ 3128 Leonardo's Notebook (置换)
Leonardo's Notebook Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2324 Accepted: 98 ...
- [Poj3128]Leonardo's Notebook
[Poj3128]Leonardo's Notebook 标签: 置换 题目链接 题意 给你一个置换\(B\),让你判断是否有一个置换\(A\)使得\(B=A^2\). 题解 置换可以写成循环的形式, ...
- LA 3641 Leonardo的笔记本 & UVA 11077 排列统计
LA 3641 Leonardo的笔记本 题目 给出26个大写字母的置换B,问是否存在要给置换A,使得 \(A^2 = B\) 分析 将A分解为几个循环,可以观察经过乘积运算得到\(A^2\)后,循环 ...
- Leonardo's Notebook UVALive - 3641(置换)
题意: 给出26个大写字母的置换B,问是否存在一个置换A,使得A2 = B 解析: 两个长度为n的相同循环相乘,1.当n为奇数时结果也是一个长度为n的循环:2. 当n为偶数时分裂为两个长度为n/2 ( ...
- LA 3641 (置换 循环的分解) Leonardo's Notebook
给出一个26个大写字母的置换B,是否存在A2 = B 每个置换可以看做若干个循环的乘积.我们可以把这些循环看成中UVa 10294的项链, 循环中的数就相当于项链中的珠子. A2就相当于将项链旋转了两 ...
- 【LA 3641】 Leonardo's Notebook (置换群)
[题意] 给出26个大写字母组成 字符串B问是否存在一个置换A使得A^2 = B [分析] 置换前面已经说了,做了这题之后有了更深的了解. 再说说置换群. 首先是群. 置换群的元素是置换,运算时是 ...
- poj 3128 Leonardo's Notebook——思路(置换)
题目:http://poj.org/problem?id=3128 从环的角度考虑. 原来有奇数个点的环,现在点数不变: 原来有偶数个点的环(设有 k 个点),现在变成两个大小为 k/2 的环. 所以 ...
- poj 3128 Leonardo's Notebook (置换群的整幂运算)
题意:给你一个置换P,问是否存在一个置换M,使M^2=P 思路:资料参考 <置换群快速幂运算研究与探讨> https://wenku.baidu.com/view/0bff6b1c6bd9 ...
随机推荐
- SQL Server2005/2008 作业执行失败的解决办法
数据库:SQL Server 2005/2008,运行环境:Windows Server 2008 在数据库里的所有作业都执行失败,包括自动执行和手动执行.在事件查看器里看到的错误报告如下: 该 作 ...
- Head First Servlets & JSP 学习笔记 第四章 —— 作为Servlet
Servlet的任务是得到一个客户的请求,再发回一个响应. 请求: 容器控制着Servlet的一生,它会创建请求和响应对象.为Servlet创建一个新线程或分配一个线程,另外调用Servlet的ser ...
- 运行./build.sh出现错误:bash: ./build.sh: Permission denied
原因:文件为只读,或者用户没有权限. 修改方法: 运行命令: chmod 777 build.sh
- windows7 Cygwin 下安装 YouCompleteMe 插件
原创文章,欢迎指正!转载请注明~ 从上周就开始想在cygwin上安装YouCompleteMe插件,按照GITHUB上的官方教程安装,由于自己的理解失误,一直搞不清是按照在windows上安装还是按照 ...
- python any() all()
any() 函数用于判断给定的可迭代参数 iterable 是否全部为 False,则返回 False,如果有一个为 True,则返回 True. 元素除了是 0.空.FALSE 外都算 TRUE. ...
- [转]C#中HttpClient使用注意:预热与长连接
最近在测试一个第三方API,准备集成在我们的网站应用中.API的调用使用的是.NET中的HttpClient,由于这个API会在关键业务中用到,对调用API的整体响应速度有严格要求,所以对HttpCl ...
- redis 哨兵(sentinel)
redis哨兵 哨兵自动故障转移 自动通知应用最新master信息 无需担心,master挂了,程序不需要修改IP啥的,由哨兵自动完成 修改sentinel.conf protected-mode n ...
- 记录ssh暴力破解的密码字典
之前我已经在wooyun和91ri上发表了这篇文章,今天转到51cto上... 默认的ssh日志是不带密码记录功能的,现在想把登录密码记录下来,这样就可以搜集黑客的ssh爆破字典了,从而可以反扫回去. ...
- Django权限系统auth
auth模块是Django提供的标准权限管理系统,可以提供用户身份认证, 用户组和权限管理. auth可以和admin模块配合使用, 快速建立网站的管理系统. 在INSTALLED_APPS中添加'd ...
- How to install VCM 2 Ford IDS 109 software
How to install Ford IDS 109: 1- Install the ids 86 before changing the date to 1 07 2015 (hold the d ...