【Codeforces 1006D】Two Strings Swaps
2024-09-06 15:48:14
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
注意只能改变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;
}
最新文章
- Modified Least Square Method and Ransan Method to Fit Circle from Data
- C# 得到sqlserver 数据库存储过程,触发器,视图,函数 的定义
- golang使用interface来mock进行测试(来自dotGO2014)
- 使用xml来显示获取的mysql数据
- ios7 自定义UINavigationBar UIBarButtonItem 10px的偏移纠正
- 值类型与引用类型(特殊的string) Typeof和GetType() 静态和非静态使用 参数传递 相关知识
- C#构造函数的 ";继承"; 问题
- VS下 dllimport与dllexport作用与区别
- InfluxDB安装和简介
- CSS之padding&;margin
- Add-Migration : 无法将“Add-Migration”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
- NodeJs相关系列文章
- SpringBoot------个性化启动Banner设置
- zookeeper 单机版配置
- iOS-获取当前View所在的控制器
- Confluence 6 选项 1 – 在 Confluence 中手动重建用户和用户组
- 《DSP using MATLAB》Problem 4.15
- include方便查找
- CLR查找和加载程序集 z
- [Node.js]32. Level 7: Working with Lists -- Redis
热门文章
- [LOJ6041雅礼集训2017]事情的相似度
- AtCoder Regular Contest 074 F - Lotus Leaves
- Codeforces Round #261 (Div. 2) D
- nth Permutation LightOJ - 1060
- Squid启动报:Could not determine this machines public hostname. Please configure one or set &#39;visible_hostname&#39;.
- [转]Intellij Idea自动添加注释的方法
- 洛谷2017 5月月赛R1
- sybase sql anywhere 5.0 安装后sybase central中无法打开视图等的解决办法
- Mysql数据库表的迁移和表的复制
- Android(java)学习笔记174:服务(service)之混合方式开启服务