题意:给定一个置换 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 (置换)的更多相关文章

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

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

  2. POJ 3128 Leonardo's Notebook (置换)

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

  3. [Poj3128]Leonardo's Notebook

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

  4. LA 3641 Leonardo的笔记本 & UVA 11077 排列统计

    LA 3641 Leonardo的笔记本 题目 给出26个大写字母的置换B,问是否存在要给置换A,使得 \(A^2 = B\) 分析 将A分解为几个循环,可以观察经过乘积运算得到\(A^2\)后,循环 ...

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

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

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

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

  7. 【LA 3641】 Leonardo's Notebook (置换群)

    [题意] 给出26个大写字母组成 字符串B问是否存在一个置换A使得A^2 = B [分析] 置换前面已经说了,做了这题之后有了更深的了解. 再说说置换群.   首先是群. 置换群的元素是置换,运算时是 ...

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

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

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

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

随机推荐

  1. Shell特殊变量:$0 $# $* $@ $? $$和命令行参数

    一.特殊变量表 变量 含义 $0 当前脚本的文件名 $n 传递给脚本或函数的参数.n 是一个数字,表示第几个参数.例如,第一个参数是$1,第二个参数是$2. $# 传递给脚本或函数的参数个数. $* ...

  2. Redhat ssh服务登录慢

    redhat在安装以后每次通过ssh服务登录,要等待几秒才能进入. 只要在sshd_config修改一下以下值就好 vim /etc/ssh/sshd_config UseDNS no service ...

  3. 左侧菜单栏,有对个li对应一个content

    html部分截图 不多说直接上js /*左侧导航栏*/var sect=$(".sect"); $(".nav-list .nav-a").each(funct ...

  4. Oracle_PL/SQL(4) 过程和函数

    create table s_sc ( SNAME VARCHAR2(20) primary key, c_grade NUMBER(6), m_grade NUMBER(6), e_grade NU ...

  5. 浏览器与服务器交互原理以及用java模拟浏览器操作v

    浏览器应用服务器JavaPHPApache * 1,在HTTP的WEB应用中, 应用客户端和服务器之间的状态是通过Session来维持的, 而Session的本质就是Cookie, * 简单的讲,当浏 ...

  6. 1C - A + B Problem II

    I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum o ...

  7. Hadoop(二) HADOOP集群搭建

    一.HADOOP集群搭建 1.集群简介 HADOOP集群具体来说包含两个集群:HDFS集群和YARN集群,两者逻辑上分离,但物理上常在一起 HDFS集群: 负责海量数据的存储,集群中的角色主要有 Na ...

  8. 希尔排序和归并排序(java实现)

    希尔排序 希尔排序算法实际上是一种特殊的插入排序,由DL.Shell于1959年提出而得名. 算法思想:希尔排序使数组中任意间隔为h的元素都是有序的,这些数组称为h有序数组,对于每个h,按插入排序进行 ...

  9. 探索未知种族之osg类生物---器官初始化四

    上一节我们对完成了对osg生物内部非常重要器官graphicsContext的初始化工作.这样就可保证我们场景中至少有一个graphicContext存在,不至于刚出生就面临夭折.我们根据上一节中os ...

  10. php中static静态关键字的使用方法和应用场景

    php中除了常规类和方法的使用,访问控制之外,还有静态关键字static,静态变量可以是局部变量也可以是全局变量,当一个程序段执行完毕时,静态变量并没有消失,它依然存在于内存中,下次在定义时还是以前的 ...