【CF1243B1】Character Swap (Easy Version)【思维】


题意:给你两个字符串,问是否存在交换方案使得两个字符串变成一样的,方案为只交换一次且只交换s1与s2里的一个字符
题解:若一开始就相同,则存在交换方案
若一开始不同的位置为1个或大于2个,则不存在方案
若一开始不同的位置为2个,则看ai==aj 或 bi==bj,只要满足其中一个就存在方案,否则不存在方案
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
using namespace std;
int T,l,cnt;
char a[],b[];
int dif[];
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%s%s",&l,a,b);cnt=;
for(int i=;i<l;i++)if(a[i]!=b[i])dif[++cnt]=i;
if(cnt> || cnt==){printf("No\n");continue;}
if(cnt==){printf("Yes\n");continue;}
if(a[dif[]]==a[dif[]] && b[dif[]]==b[dif[]])printf("Yes\n");
else printf("No\n");
}
return ;
}
【CF1243B1】Character Swap (Easy Version)【思维】的更多相关文章
- Codeforces Round #599 (Div. 2) B1. Character Swap (Easy Version) 水题
B1. Character Swap (Easy Version) This problem is different from the hard version. In this version U ...
- Codeforces Round #599 (Div. 2) B1. Character Swap (Easy Version)
This problem is different from the hard version. In this version Ujan makes exactly one exchange. Yo ...
- Codeforces Round #599 (Div. 2) B2. Character Swap (Hard Version) 构造
B2. Character Swap (Hard Version) This problem is different from the easy version. In this version U ...
- Codeforces Round #599 (Div. 2) B2. Character Swap (Hard Version)
This problem is different from the easy version. In this version Ujan makes at most 2n2n swaps. In a ...
- 【CF1243B2】Character Swap (Hard Version)【思维】
题意:给定两个字符串,问是否存在交换方案使得两个字符串相同,方案为交换次数小于等于2n,且每次只交换s1与s2中的一个字符 题解:考虑从前往后枚举,当第i位不同时,考虑找后边的第j位,若存在这样的第j ...
- B2. Character Swap (Hard Version)
链接: http://codeforces.com/contest/1243/problem/B2 题目大意: 两个字符串,判断能否通过交换为从而使得这两个字符串完全一致,如不可以的话,直接输出NO, ...
- CodeForces 1243"Character Swap (Hard Version)"(multimap)
传送门 •前置知识-multimap的用法 $multimap$ 与 $map$ 的区别在于一个 $key$ 可以对应几个值: 对于 $map$ 而言,一个 $key$ 只能对应一个值,并且按照 $k ...
- Codeforces Round #575 (Div. 3) D1+D2. RGB Substring (easy version) D2. RGB Substring (hard version) (思维,枚举,前缀和)
D1. RGB Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inp ...
- ZOJ 3868 - Earthstone: Easy Version
3868 - Earthstone: Easy Version Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld ...
随机推荐
- 阶段1 语言基础+高级_1-3-Java语言高级_04-集合_06 Set集合_1_HashSet集合介绍
特点:不允许有重复的记录,无序的集合 set不允许重复.接口中没有索引.所以方法和Collection中的方法是一样的,没有带索引的方法 因为Set的方法和Collection都是一样的.所以这里不再 ...
- 测开之路九十一:css常用的选择器
一:全局选择器:* 二:标签选择器,如给所有p标签加个背景色 三:id选择器:# ,如给id为id_01的元素加一个框 四:类选择器:. 如设置一个类选择器为blue,当有标签引用blue的时候,背景 ...
- 2019了,给自己立一个flag吧
新年伊始,元旦已过,虽然有迟了,但是,相对于整年来说,还是比较早.年度总结,年度规划,除过上交的报告以外,还得自己给自己立个flag,一次来督促自己,而不是为了别的.做这些事,不仅仅是为了能更好的工作 ...
- vue中的computed 与 watch
计算属性 computed 指通过计算得来的属性,用于监听属性的变化 computed里面的函数调用的时候 不需要加() 方法里必须有一个返回值 return computed中的函数不会通过事件去触 ...
- git比较重要但是又容易忘记的操作
git rebase head~1 把多次commit合并成一次 git reset head 撤销已缓存的内容 git checkout . git stash 去除改动未提交的代码
- Sentinel之熔断降级
除了流量控制以外,对调用链路中不稳定的资源进行熔断降级也是保障高可用的重要措施之一.由于调用关系的复杂性,如果调用链路中的某个资源不稳定,最终会导致请求发生堆积.Sentinel 熔断降级会在调用链路 ...
- [2019杭电多校第七场][hdu6656]Kejin Player
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6656 题意为从i级花费a元有p的概率升到i+1级,有1-p的概率降到x级(x<i),查询从L级升 ...
- INPUT输入子系统——按键
一.什么是input输入子系统? 1.1. Linux系统支持的输入设备繁多,例如键盘.鼠标.触摸屏.手柄或者是一些输入设备像体感输入等等,Linux系统是如何管理如此之多的不同类型.不同原理.不同的 ...
- [AHOI2013]作业 (莫队+分块)
[AHOI2013]作业 (莫队+分块) 题面 给定了一个长度为n的数列和若干个询问,每个询问是关于数列的区间[l,r],首先你要统计该区间内大于等于a,小于等于b的数的个数,其次是所有大于等于a,小 ...
- [集合]List
List 存取有序,有索引,可以重复 ArrayList去除集合中字符串的重复值(字符串的内容相同) public static void main(String[] args) { ArrayLis ...