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 ...
随机推荐
- jquery ajax 中实现给变量赋值
我们在用JQuery的Ajax从后台提取数据后想把它赋值给全局变量,但是却怎么都赋不进,为什么呢? 原因其实很简单,我们用的Ajax是异步操作,也就是说在你赋值的时候数据还没提取出来,你当然赋不进去, ...
- js原生语法实现表格操作
HTML页面: <!doctype html> <html lang="en"> <head> <meta charset="U ...
- PAT 1005 继续(3n+1)猜想 (25)(代码)
1005 继续(3n+1)猜想 (25)(25 分) 卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下 ...
- Java.Class
Class类 1. Class继承自Object. 2. .class 和 instance.getClass()的区别 Ref[1] Reference 1. .class http://stack ...
- Business.Startup.Learning from Startup Mistakes at SpringSource
http://www.infoq.com/news/2014/07/startup-spring
- Games.RecordMobileGamePlayVideo
1. kamcord https://github.com/kamcord/ 2. Sound Stage & iSimulate http://blog.tacograveyard.com/ ...
- javascript 高级程序设计 六
上一节还有一个注意的地方:建议所有函数的必需参数使用命名参数,而非必须的参数使用对象来封装. 通过这几天的读书,发现了一个深入了解所学知识的一个捷径——读书.本来我在计算机这方法的所有知识一般都是从视 ...
- Numpy 学习 array np.where lexsort 切片 按行按列求平均mean
array 的创建可以通过list给 array print出来像一个表格,可以按行按列来观察. 原来是一个list相当于一行 np.where用于寻找一个condition下的坐标,返回的是一个2个 ...
- Python generator 的yield (enumerate)
生成杨辉三角 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 def triangles(max): L = [1,] while len(L) - 1 < ...
- How to Change MAC Address on Ubuntu
1 Open Terminal. 2 Log in as root so type: sudo -i and then write your password. 3 View your cur ...