题意:给你两个字符串,问是否存在交换方案使得两个字符串变成一样的,方案为只交换一次且只交换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. 阶段1 语言基础+高级_1-3-Java语言高级_1-常用API_1_第1节 Scanner类_4-练习一_键盘输入两个数

    导包语句其实不用我们自己去写, 选中后回车会自动的导入包 java.util 如果没有导入进来也可以,光标在关键字那里,ALT+回车 也会自动导入包 运行看一下结果:程序其实还有可以优化的地方 先输入 ...

  2. python中的包和文件夹的区别

    python的模块,就不得不说包(package),package是module的集合,在一个package中有很多的module, 还是以之前的index.py与baiduHq.py模块为案例,说明 ...

  3. 【FICO系列】SAP FICO 基本概念

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[FICO系列]SAP FICO 基本概念   ...

  4. SpringCloud启动Eureka server时报错 java.lang.TypeNotPresentException: Type javax.xml.bind.JAXBContext not present

    SpringBoot打开Eureka server时出现以下错误: java.lang.TypeNotPresentException: Type javax.xml.bind.JAXBContext ...

  5. LeetCode——707 设计链表

    题目: 总而言之就是要用C++手撸链表,我的代码: class MyLinkedList { public: /** Initialize your data structure here. */ M ...

  6. OO第四单元总结及课程总结

    OO第四单元总结及课程总结 一.前言 紧张刺激的OO“昆仑课程”接近尾声,经过一个学期的学习,我的收获和感触颇多,借此博客作业的机会,对自己OO这门课程做一个总结.本博客主要有以下五个方面,一是第UM ...

  7. windows和linux中查看端口占用情况并kill掉对应进程

    好几次在不同的情况下遇到 需要查看端口信息 并且kill掉对应进程的情况 相关的参数总是记不全 在这里记录下 以后查看方便 windows中查看正在使用端口的信息netstat -ano|findst ...

  8. [Python3 填坑] 006 “杠零”,空字符的使用

    目录 1. print( 坑的信息 ) 2. 开始填坑 2.1 \0 是空字符,输出时看不到它,但它占 1 个字符的长度 2.2 \0 "遇八进制失效" 2.3 \0 与 '' 不 ...

  9. [Codeforces 1205B]Shortest Cycle(最小环)

    [Codeforces 1205B]Shortest Cycle(最小环) 题面 给出n个正整数\(a_i\),若\(a_i \& a_j \neq 0\),则连边\((i,j)\)(注意i- ...

  10. 搜索---DFS

    DFS   广度优先一层一层遍历,每一层得到的所有新节点,要用队列存储起来以备下一层遍历的时候再遍历.   而深度优先遍历搜索在得到一个新节点时立即对新节点进行遍历:从节点0出发开始遍历,得到新节点6 ...