Equalizing Two Strings CodeForces - 1256F (思维)
大意: 给定两个串$s,t$, 每次操作任选长度$len$, 分别翻转$s,t$中一个长$len$的子串, 可以进行任意次操作, 求判断能否使$s$和$t$相同.
字符出现次数不一样显然无解, 否则若某种字符出现多次, 显然有解, 否则只要逆序对奇偶性相同就有解, 不同则无解.
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 1e6+10;
char s1[N],s2[N];
int n; void work() {
scanf("%d%s%s",&n,s1+1,s2+1);
map<int,int> a1,a2;
REP(i,1,n) ++a1[s1[i]],++a2[s2[i]];
if (a1!=a2) return puts("NO"),void();
for (auto &t:a1) if (t.y>=2) return puts("YES"),void();
int f1=0,f2=0;
REP(i,1,n) REP(j,1,i-1) f1+=s1[j]>s1[i],f2+=s2[j]>s2[i];
puts((f1^f2)&1?"NO":"YES");
} int main() {
int t;
scanf("%d", &t);
while (t--) work();
}
Equalizing Two Strings CodeForces - 1256F (思维)的更多相关文章
- Codeforces Round #598 (Div. 3) F. Equalizing Two Strings 构造
F. Equalizing Two Strings You are given two strings s and t both of length n and both consisting of ...
- Equalizing Two Strings
F. Equalizing Two Strings 有几种情况可以直接判定结果: ① 字母对应个数不一样,可直接判NO ② 当不满足①时,如果有一个字母有2个及以上的个数,也可直接判YES ③ 当不满 ...
- Codeforces Round #598 (Div. 3) F. Equalizing Two Strings
You are given two strings ss and tt both of length nn and both consisting of lowercase Latin letters ...
- Codeforces 424A (思维题)
Squats Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Statu ...
- 3-palindrome CodeForces - 805B (思维)
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so ...
- Codeforces 1060E(思维+贡献法)
https://codeforces.com/contest/1060/problem/E 题意 给一颗树,在原始的图中假如两个点连向同一个点,这两个点之间就可以连一条边,定义两点之间的长度为两点之间 ...
- Queue CodeForces - 353D (思维dp)
https://codeforces.com/problemset/problem/353/D 大意:给定字符串, 每一秒, 若F在M的右侧, 则交换M与F, 求多少秒后F全在M左侧 $dp[i]$为 ...
- [USACO12NOV]同时平衡线Concurrently Balanced Strings DP map 思维
题面 [USACO12NOV]同时平衡线Concurrently Balanced Strings 题解 考虑DP. \(f[i]\)表示以\(i\)为左端点的合法区间个数.令\(pos[i]\)表示 ...
- D. Huge Strings Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
http://codeforces.com/contest/868/problem/D 优化:两个串合并 原有状态+ 第一个串的尾部&第二个串的头部的状态 串变为第一个串的头部&第二个 ...
随机推荐
- 为什么学习JavaScript设计模式,因为它是核心
那么什么是设计模式呢?当我们在玩游戏的时候,我们会去追求如何最快地通过,去追求获得已什么高效率的操作获得最好的奖品:下班回家,我们打开手机app查询最便捷的路线去坐车:叫外卖时候,也会找附近最近又实惠 ...
- python 类的倒入
test.pyclass sss: def ddd(self): print("hello") test2.pyfrom testone import sss
- python: isdigit int float 使用
>>> num1 = '2.0' >>> print num1.isdigit() False >>> num2 = ' >>> ...
- Flask纪要
flask学习过程 1框架基础 2redis高性能key-value数据库 3视图具有装饰器的路由函数 4模板html文件 面向对象操作数据库orm 5蓝图 6单元测试 7GitHub 8项目 学习的 ...
- 1045-Access denied for user 'root'@'localhost'解决方法
1.出现这个问题的原因之一是权限的问题,也就是说你的电脑可能没有权限访问mysql数据库. 讲道理这种情况其实基本上不该遇到,因为我们在安装mysql之后,root其实是有最高权限的,而且很少会有人去 ...
- RocketMQ常用命令【转】
首先进入 RocketMQ 工程,进入/RocketMQ/bin 在该目录下有个 mqadmin 脚本 . 查看帮助: 在 mqadmin 下可以查看有哪些命令 a: 查看具体命令的使用 : ...
- web项目脱敏白名单管理
写在前面 下午没事, 看一下同事写的脱敏白名单管理功能. 所谓的脱敏就是将页面中查询出的信息列表当中的身份证号及手机号等关键信息部分用*号代替.该功能主要思路是新增一个页面用于配置哪些页面以及页面中哪 ...
- t6_sumdoc
C:\Users\Administrator\Documents\sumdoc 2019\sumdoc t6 final\sumdoc t615C:\Users\Administrator\Docum ...
- [转]import xxx from 和 import {xxx} from的区别
原文地址:https://www.cnblogs.com/Abner5/p/7256043.html 1.vue import FunName from ‘../xxx’ 1.js export de ...
- WebGL学习笔记(九):阴影
3D中实现实时阴影技术中比较常见的方式是阴影映射(Shadow Mapping),我们这里也以这种技术来实现实时阴影. 阴影映射背后的思路非常简单:我们先以光的位置为视角进行渲染,我们能看到的东西都将 ...