【Codeforces 1006D】Two Strings Swaps
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
注意只能改变a不能改变b
然后只要让a[i],b[i],a[n-i-1],b[n-i-1]这4个字符能凑成两对、全都一样就可以了
分类讨论下就好
【代码】
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 300;
int n;
string s1,s2;
map<char,int> dic,dic1;
int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> n;
cin >> s1;
cin >> s2;
int cnt = 0;
for (int i = 0;i < n/2;i++){
dic.clear();dic1.clear();
dic[s1[i]]++;
dic[s1[n-i-1]]++;
dic1[s2[i]]++;
dic1[s2[n-i-1]]++;
int k1 = dic.size(),k2 = dic1.size();
if (k1==1 && k2==1){
cnt+=0;
}
if (k1==1 && k2==2){
dic1[s1[i]] = 1;
int t = dic1.size();
if (t==k2){
cnt++;
}else cnt+=2;
}
if (k1==2 && k2==1){
dic[s2[i]] = 1;
cnt++;
}
if (k1==2 && k2==2){
dic[s2[i]] = 1;
dic[s2[n-i-1]] = 1;
int t = dic.size();
if (t>k1+1){
cnt+=2;
}else if (t>k1){
cnt++;
}else cnt+=0;
}
}
if (n%2==1){
if (s1[n/2]!=s2[n/2]){
cnt++;
}
}
cout<<cnt<<endl;
return 0;
}
【Codeforces 1006D】Two Strings Swaps的更多相关文章
- 【24.34%】【codeforces 560D】Equivalent Strings
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 798B】Mike and strings
[题目链接]:http://codeforces.com/contest/798/problem/B [题意] 给你n个字符串; 每次操作,你可以把字符串的每个元素整体左移(最左边那个字符跑到最后面去 ...
- 【52.49%】【codeforces 556A】Case of the Zeros and Ones
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【19.46%】【codeforces 551B】ZgukistringZ
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 755B】PolandBall and Game
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 750E】New Year and Old Subsequence
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 761C】Dasha and Password(动态规划做法)
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 761C】Dasha and Password(贪心+枚举做法)
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- Python while 1 和 while True 速度比较
References http://legacy.python.org/dev/peps/pep-0285/http://stackoverflow.com/questions/3815359/whi ...
- Hdu 2888 Check Corners (二维RMQ (ST))
题目链接: Hdu 2888 Check Corners 题目描述: 给出一个n*m的矩阵,问以(r1,c1)为左上角,(r2,c2)为右下角的子矩阵中最大的元素值是否为子矩阵的顶点? 解题思路: 二 ...
- linux系统文件目录解析
/bin 二进制可执行命令 /dev 设备文件(硬盘/光驱等) /etc 系统管理和配置文件 /etc/rc.d 启动的配置文件和脚本 /home 用户主目录,下面会有以登录用户名作为文件夹名 ...
- 简单记录下@RequestBody(关于它和@RequestParam接收数据方式的拓展)
内容参考自博客:https://blog.csdn.net/ff906317011/article/details/78552426 这个标注是用来注释controller中的请求方法中的参数的,那么 ...
- webkit滤镜
-webkit-filter: grayscale(1);/*灰度*/ -webkit-filter: sepia(1);/*褐色*/ -webkit-filter: saturate(1);/*饱和 ...
- HDU 5778 abs 数学
http://acm.hdu.edu.cn/showproblem.php?pid=5778 这题的意思就是找离x最近的一个数y,且y是一个完全平方数,还是所有质因子都只能出现两次的完全平方数 一开始 ...
- R语言中的并行处理
网上有人说foreach包可以并行,我就去弄了,结果发现一个普通的二重循环什么事都不错都很卡!捣鼓了半天才发现是foreach的问题 为了提速,做了如下事宜: 直接利用矩阵列加减,不是一个个遍历加 把 ...
- jmeter压测--从文本中读取参数
由于之前从数据库获取查询结果作为请求的入参(使用场景:测试一个接口并发处理数据的能力,并且每次请求传入的参数都要不同.),会一定程度上造成对数据库的压测,在没有完全搞清楚多线程之间参数的传递之前,我们 ...
- js事件、Js中的for循环和事件的关系、this
一.js事件 1.事件 用户在网页中所触发的行为 鼠标滑动种类很多,键盘.表单特列: 点击:onclick 鼠标进入:onmouseenter 鼠标离开:onmouseleave 鼠标悬浮:onmo ...
- vmware让虚拟机内外网络可互访
以下方法可使主机可以ping通虚拟机,虚拟机也可以ping通主机 首先对虚拟机设置 然后设置虚拟机,假设主机的ip是10.0.0.9,那虚拟机的ip应如下设置: 其中ip地址任意设置一个,但要求跟主机 ...