标签:\n -- code base sign tor ++ sync max
题意:
给出26个大写字母的置换B,问是否存在一个置换A,使得A2 = B
解析:
两个长度为n的相同循环相乘,1、当n为奇数时结果也是一个长度为n的循环;2、 当n为偶数时分裂为两个长度为n/2 (这个n/2可能是奇数 也可能是偶数)的循环
那么倒推 意思也就是说 对于长度为奇数的循环B(奇数个相同长度的倒推1 偶数个相同长度的倒推2) 总可以找出来一个循环A 使得A2 = B
而对于长度为偶数的循环B 只有偶数个相同长度的才能从2倒推 不然 就不能倒推 即找不到一个A使得A2 = B
#include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <cctype> #include <set> #include <vector> #include <stack> #include <queue> #include <algorithm> #include <cmath> #include <bitset> #define rap(i, a, n) for(int i=a; i<=n; i++) #define rep(i, a, n) for(int i=a; i<n; i++) #define lap(i, a, n) for(int i=n; i>=a; i--) #define lep(i, a, n) for(int i=n; i>a; i--) #define rd(a) scanf("%d", &a) #define rlld(a) scanf("%lld", &a) #define rc(a) scanf("%c", &a) #define rs(a) scanf("%s", a) #define pd(a) printf("%d\n", a); #define plld(a) printf("%lld\n", a); #define pc(a) printf("%c\n", a); #define ps(a) printf("%s\n", a); #define MOD 2018 #define LL long long #define ULL unsigned long long #define Pair pair<int, int> #define mem(a, b) memset(a, b, sizeof(a)) #define _ ios_base::sync_with_stdio(0),cin.tie(0) //freopen("1.txt", "r", stdin); using namespace std; const int maxn = 10010, INF = 0x7fffffff, LL_INF = 0x7fffffffffffffff; string str; int vis[maxn], bz[maxn]; int main() { int T; rd(T); while(T--) { cin >> str; mem(vis, 0); mem(bz, 0); for(int i = 0; i < 26; i++) { int idx = str[i] - ‘A‘; int cnt = 0; while(!vis[idx]) { cnt++; vis[idx] = 1; idx = str[idx] - ‘A‘; } bz[cnt]++; } int flag = 1; for(int i = 2; i < 26; i += 2) if(bz[i] & 1) flag = 0; if(flag) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
Leonardo's Notebook UVALive - 3641(置换)
标签:\n -- code base sign tor ++ sync max
原文地址:https://www.cnblogs.com/WTSRUVF/p/9736022.html