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 ...
随机推荐
- for all entries
1.必须要判断for all entries in后面的内表是否为空,如果为空,where条件中与内表中字段进行比较的结果全部为真,会导致取出非常多的数据,影响系统性能.2.使用for all ent ...
- AnguarJS——第10章 路由
第10章 路由 一个应用是由若个视图组合而成的,根据不同的业务逻辑展示给用户不同的视图,路由则是实现这一功能的关键. 10.1 SPA SPA(Single Page Application)指的是通 ...
- spring源码分析(一)
一.首先分析AliasRegistry接口. 1.Alias别名,Registry注册表,AliasRegistry别名注册表接口. 2.共有四个方法,注册别名,判断是否别名,获取别名数组,移除别名. ...
- 利用jenkins+saltstack+sh 修改nginx配置文件并重新加载
jenkins的配置(这里作用只是当做界面使用,利用它来管理执行salt命令) 1.构建操作来执行shell脚本 (pillar可以配置灵活的参数) saltstack 的 sls文件编写 nginx ...
- win下svn常用操作笔记
svn基本命令 checkout 检出 把服务器代码下载到本地一份update 更新 把服务器上的最新代码更新到本地commit 提交 把本地代码提交到服务器上 win下svn的客户端工具Tortoi ...
- C语言 内存
内存属性: 1.大小 2.位置 int a; 默认方式 (段) 内核空间 应用程序不许访问 ------------------------------------------3g ...
- PAT 1021 个位数统计 (15)(C++&Java&Python)
1021 个位数统计 (15)(15 分) 给定一个k位整数N = d~k-1~*10^k-1^ + ... + d~1~*10^1^ + d~0~ (0<=d~i~<=9, i=0,.. ...
- Activity2.java
package com.hanqi.text3; import android.app.Activity; import android.os.Bundle; import android.os.Pe ...
- Java.FamousBlogs
本文总结在工作/学习中发现的Java相关的blogs. 1. java code geeks (jcg) http://www.javacodegeeks.com/join-us/jcg/ 2. ht ...
- git报“commiter email "root@localhost.localdomain"does not match your user account”
首先检查账户邮箱配置是否正确,检查方法: git config --list 发现邮箱及帐号配置正确,但是git push时仍然报如题错误: 原因:git执行add.commit 时已经记录下了做了该 ...