题意:给你两个字符串,问是否存在交换方案使得两个字符串变成一样的,方案为只交换一次且只交换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)【思维】的更多相关文章

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

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

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

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

  5. 【CF1243B2】Character Swap (Hard Version)【思维】

    题意:给定两个字符串,问是否存在交换方案使得两个字符串相同,方案为交换次数小于等于2n,且每次只交换s1与s2中的一个字符 题解:考虑从前往后枚举,当第i位不同时,考虑找后边的第j位,若存在这样的第j ...

  6. B2. Character Swap (Hard Version)

    链接: http://codeforces.com/contest/1243/problem/B2 题目大意: 两个字符串,判断能否通过交换为从而使得这两个字符串完全一致,如不可以的话,直接输出NO, ...

  7. CodeForces 1243"Character Swap (Hard Version)"(multimap)

    传送门 •前置知识-multimap的用法 $multimap$ 与 $map$ 的区别在于一个 $key$ 可以对应几个值: 对于 $map$ 而言,一个 $key$ 只能对应一个值,并且按照 $k ...

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

  9. ZOJ 3868 - Earthstone: Easy Version

    3868 - Earthstone: Easy Version Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld ...

随机推荐

  1. webpack构建项目连接本机IP仍无法访问问题

    通过连接IP地址,确定连接成功后仍无法访问本机运行项目,需要对项目配置进行修改,有两种情况: 第一种是在config/index.js,把module.exports={}中找到 host:'loca ...

  2. jmeter逻辑控制器详解(2)

    逻辑控制器 8.Runtime Controller 运行周期控制器,顾名思义,这是一种设置运行时间的控制器,它的效果就是使该控制器下的子项运行时间为[Runtime]中的数值(单位:s). Runt ...

  3. Mbox-React Native

    Mbox-React Native 学习网址:https://www.jianshu.com/p/bbf9837443f3 MboX环境配置: .npm i mobx mobx-react --sav ...

  4. SVN检出新项目

    1.新建文件夹SourseCode -->打开SourseCode文件夹,右键空白处 ---> 选择SVN Checkout --选择URL of repository,选择Checkou ...

  5. jsp自定义标签处理转义字符

    sun公司提供的jstl虽然比较强大,但是开发中很难满足我们所有的需求,并且开发也禁止在jsp中写很多java代码,因此很多场景需要自己定义标签进行项目开发 sun提供的标签库引用方式:<%@t ...

  6. sublime text3插件安装及使用

    sublime官网下载地址:http://www.sublimetext.com/ 我用的是SubLime text3,插件安装命令地址:https://packagecontrol.io/insta ...

  7. Webstorm上已有的本地项目上传到Github

    1.Webstorm左上角File —— Settings—— Github, Auth Type改成password,在Login和Password中输入自己的github账户和密码,点Test测试 ...

  8. Git:将本地项目连接到远程(github、gitee、gitlab)仓库流程

    当进行协同开发或者为了代码安全备份需要,一般都会将本地代码和远程仓库相连接. 备注:Github.Gitee.Gitlab是三个常用的远程git仓库,操作流程基本一致. 提前环境要求: 1.node. ...

  9. 第一个chrome extension

    如今,chrome浏览器的使用如越来越流行,chrome extension往往能提供更多很丰富的功能.以前一直想了解这方面的东西,可是又担心很复杂.前段时间,在斗鱼看一个直播,想刷弹幕,但是每次自己 ...

  10. js中reduce()的牛掰所在 本质作用:实现数值累计,筛选过滤,类似递归

      先看w3c官说   array.reduce(function(total, currentValue, currentIndex, arr), initialValue); /* total: ...