大意: 给定两个串$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 (思维)的更多相关文章

  1. 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 ...

  2. Equalizing Two Strings

    F. Equalizing Two Strings 有几种情况可以直接判定结果: ① 字母对应个数不一样,可直接判NO ② 当不满足①时,如果有一个字母有2个及以上的个数,也可直接判YES ③ 当不满 ...

  3. 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 ...

  4. Codeforces 424A (思维题)

    Squats Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Statu ...

  5. 3-palindrome CodeForces - 805B (思维)

    In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so ...

  6. Codeforces 1060E(思维+贡献法)

    https://codeforces.com/contest/1060/problem/E 题意 给一颗树,在原始的图中假如两个点连向同一个点,这两个点之间就可以连一条边,定义两点之间的长度为两点之间 ...

  7. Queue CodeForces - 353D (思维dp)

    https://codeforces.com/problemset/problem/353/D 大意:给定字符串, 每一秒, 若F在M的右侧, 则交换M与F, 求多少秒后F全在M左侧 $dp[i]$为 ...

  8. [USACO12NOV]同时平衡线Concurrently Balanced Strings DP map 思维

    题面 [USACO12NOV]同时平衡线Concurrently Balanced Strings 题解 考虑DP. \(f[i]\)表示以\(i\)为左端点的合法区间个数.令\(pos[i]\)表示 ...

  9. D. Huge Strings Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)

    http://codeforces.com/contest/868/problem/D 优化:两个串合并 原有状态+ 第一个串的尾部&第二个串的头部的状态 串变为第一个串的头部&第二个 ...

随机推荐

  1. 计蒜客 41387.XKC's basketball team-线段树(区间查找大于等于x的最靠右的位置) (The Preliminary Contest for ICPC Asia Xuzhou 2019 E.) 2019年徐州网络赛

    XKC's basketball team XKC , the captain of the basketball team , is directing a train of nn team mem ...

  2. 实践分布式配置中心Apollo

    简介 Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理应用不同环境.不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限.流程治理等特性,适用于微服务配置管理场景 ...

  3. IO多路复用之Reactor

    参考文档: http://blog.csdn.net/u013074465/article/details/46276967 https://www.cnblogs.com/ivaneye/p/573 ...

  4. Redis内存数据库

    remote dictionary server 远程字典服务器 Redis默认支持16个数据库,不同的应用应该使用不同的Redis实例存储数据.   支持数据类型:字符串,哈希散列,列表,集合,有序 ...

  5. TypeScript in 5 minutes

    https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html Let’s get started by build ...

  6. python skimage图像处理(三)

    python skimage图像处理(三) This blog is from: https://www.jianshu.com/p/7693222523c0  霍夫线变换 在图片处理中,霍夫变换主要 ...

  7. vmware ubuntu16 启动蓝屏屏幕闪

    vmware ubuntu16 启动蓝屏屏幕闪 虚拟机安装了ubuntu16 desktop,没有关闭自动更新: 结果关机虚拟机时出现等5秒更新,类似win10关机更新: 再开机发现就蓝屏了,多次重启 ...

  8. 使用 Microsoft.Web.Administration 管理iis

    How to Automate IIS 7 Configuration with .NET How to Automate IIS 7 Configuration with .NET Are you ...

  9. 【NWJS】解析node-webkit(NWJS)的打包和发布

    目录结构: contents structure [-] 下载和安装node-webkit 建立一个简单的WEB应用 生成EXE可执行文件 修改icon 封包 Enigma Virtual Box I ...

  10. Xamarin.FormsShell基础教程(9)Shell相关类体系

    Xamarin.FormsShell基础教程(9)Shell相关类体系 在Shell中,最为主要的类是Shell类.Shell类实现了大多数应用程序所需的基本UI功能的页面.除此以外,常用的类还有Sh ...