Codeforces Round #498 (Div. 3) D. Two Strings Swaps (思维)
题意:给你两个长度相同的字符串\(a\)和\(b\),你可以将相同位置上的\(a\)和\(b\)的字符交换,也可以将\(a\)或\(b\)中某个位置和对应的回文位置上的字符交换,这些操作是不统计的,你可以将\(a\)的某个字符替换,操作数+1,然后可以执行上文的操作,问最少操作多少次,使得\(a\)和\(b\)相等.
题解:我们只对\(a_{i},a_{n-i+1},b_{i},b_{n-i-1}\)进行判断,如果这\(4\)个数各不相同,那么就需要修改2个\(a\),如果有\(3\)个不相同,分两个\(a\)是否相同来讨论,如果有\(2\)个不相同,分\(1+3\)和\(2+2\)来讨论即可.
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL; int n;
string a,b;
map<int,int> mp;
int main() {
ios::sync_with_stdio(false);cin.tie(0);
cin>>n>>a>>b;
int cnt=0;
for(int i=0;i<n/2;++i){
mp.clear();
mp[a[i]]++;mp[a[n-i-1]]++;
mp[b[i]]++;mp[b[n-i-1]]++;
if(mp.size()==4) cnt+=2;
else if(mp.size()==3){
if(a[i]==a[n-i-1]) cnt+=2;
else cnt++;
}
else{
if(mp[a[i]]==3||mp[b[i]]==3) cnt++;
}
}
if(n&1){
if(a[n/2]!=b[n/2]) cnt++;
}
printf("%d\n",cnt); return 0;
}
Codeforces Round #498 (Div. 3) D. Two Strings Swaps (思维)的更多相关文章
- Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)
Codeforces Round #521 (Div. 3) E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...
- Codeforces Round #498 (Div. 3) 简要题解
[比赛链接] https://codeforces.com/contest/1006 [题解] Problem A. Adjacent Replacements [算法] 将序列中的所有 ...
- Codeforces Round #313 (Div. 1) B. Equivalent Strings
Equivalent Strings Problem's Link: http://codeforces.com/contest/559/problem/B Mean: 给定两个等长串s1,s2,判断 ...
- Codeforces Round #313 (Div. 2) D. Equivalent Strings
D. Equivalent Strings Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/ ...
- Codeforces Round #313 (Div. 1) B. Equivalent Strings DFS暴力
B. Equivalent Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559 ...
- Codeforces Round #302 (Div. 1) C. Remembering Strings DP
C. Remembering Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #302 (Div. 1) C - Remembering Strings 状压dp
C - Remembering Strings 思路:最关键的一点是字符的个数比串的个数多. 然后就能状压啦. #include<bits/stdc++.h> #define LL lon ...
- (原创)Codeforces Round #550 (Div. 3) A Diverse Strings
A. Diverse Strings time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- CodeForces Round #498 Div.3 A. Adjacent Replacements
http://codeforces.com/contest/1006/problem/A Mishka got an integer array aa of length nn as a birthd ...
随机推荐
- git 遇到 fatal: loose object xxxx (stored in .git/objects/cb/xxxx) is corrupt 问题
我的git版本是2.3.x,用下面这个参考链接的方法也可以解决 参考blog
- Burp suite的系列介绍 (1)
前言 为了进行Web安全方面的学习,Burp suite是必备的工具之一,我们将会从多个模块进行逐步的学习. Burp suite的应用场景 1.HTTP服务端接口测试. 2.HTTP客户端和HTTP ...
- 一文带你学会AQS和并发工具类的关系2
1.创建公平锁 1.使用方式 Lock reentrantLock = new ReentrantLock(true); reentrantLock.lock(); //加锁 try{ // todo ...
- 【Python】国内pip节点
pip在国内使用国内节点: http://pypi.douban.com/simple 现在已经无法使用了,新版的python3需要使用https://pypi.douban.com/simple/ ...
- 【System】进程,线程和任务之间的区别是什么?
任务(task)是最抽象的,是一个一般性的术语,指由软件完成的一个活动.一个任务既可以是一个进程,也可以是一个线程.简而言之,它指的是一系列共同达到某一目的的操作.例如,读取数据并将数据放入内存中.这 ...
- 利用iptables防火墙保护web服务器
实例:利用iptables防火墙保护web服务器 防火墙--->路由器-->交换机-->pc机 配置之前,清空下已有的规则,放在规则冲突不生效 工作中,先放行端口写完规则,再DROP ...
- MSDOS(MBR)和GPT磁盘分区表
MBR和GPT分区 MBR分区:以磁盘的第一个扇区(512byte)记录分区表,其中,446byte存储开机管理程序(MBR 主要开机记录),64byte用于存放分区表 分区实际上是对分区表的修改 M ...
- 【转】自定义ALV控件的工具条按钮
1 CLASS lcl_event_receiver DEFINITION DEFERRED. 2 3 DATA: itab TYPE TABLE OF spfli, 4 wa TYPE spfli. ...
- Lakehouse: 统一数据仓库和高级分析的新一代开放平台
1. 摘要 数仓架构在未来一段时间内会逐渐消亡,会被一种新的Lakehouse架构取代,该架构主要有如下特性 基于开放的数据格式,如Parquet: 机器学习和数据科学将被作为头等公民支持: 提供卓越 ...
- 阿里面试常问的redis数据结构,建议收藏
关于Redis redis是一个开源的使用C语言编写的一个kv存储系统,是一个速度非常快的非关系远程内存数据库.它支持包括String.List.Set.Zset.hash五种数据结构.除此之外,通过 ...