Codeforces Round #498 (Div. 3) D. Two Strings Swaps(思维,多种情况讨论)

Cadence Allegro实战:如何精准导入结构DXF文件避免安装偏差(附图层配置技巧) 本文详细讲解了在Cadence Allegro中精准导入结构DXF文件以避免安装偏差的实战技巧。核心在于导入前的单位校准、创建专用图层结构,以及基于坐标基准点的精确对齐方法。文章还分享了将DXF图形转化为正式板框和禁布区、高效管理图层以及向结构工程师导出DXF的完整流程,帮助PCB工程师确保设计与机械结构完美契合。 阅读详情

D. Two Strings Swaps

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given two strings aa and bb consisting of lowercase English letters, both of length nn. The characters of both strings have indices from 11 to nn, inclusive.

You are allowed to do the following changes:

  • Choose any index ii (1≤i≤n1≤i≤n) and swap characters aiai and bibi;
  • Choose any index ii (1≤i≤n1≤i≤n) and swap characters aiai and an−i+1an−i+1;
  • Choose any index ii (1≤i≤n1≤i≤n) and swap characters bibi and bn−i+1bn−i+1.

Note that if nn is odd, you are formally allowed to swap a⌈n2⌉a⌈n2⌉ with a⌈n2⌉a⌈n2⌉ (and the same with the string bb) but this move is useless. Also you can swap two equal characters but this operation is useless as well.

You have to make these strings equal by applying any number of changes described above, in any order. But it is obvious that it may be impossible to make two strings equal by these swaps.

In one preprocess move you can replace a character in aa with another character. In other words, in a single preprocess move you can choose any index ii (1≤i≤n1≤i≤n), any character cc and set ai:=cai:=c.

Your task is to find the minimum number of preprocess moves to apply in such a way that after them you can make strings aa and bb equal by applying some number of changes described in the list above.

Note that the number of changes you make after the preprocess moves does not matter. Also note that you cannot apply preprocess movesto the string bb or make any preprocess moves after the first change is made.

Input

The first line of the input contains one integer nn (1≤n≤1051≤n≤105) — the length of strings aa and bb.

The second line contains the string aa consisting of exactly nn lowercase English letters.

The third line contains the string bb consisting of exactly nn lowercase English letters.

Output

Print a single integer — the minimum number of preprocess moves to apply before changes, so that it is possible to make the string aa equal to string bb with a sequence of changes from the list above.

Examples

input

Copy

7
abacaba
bacabaa

output

Copy

4

input

Copy

5
zcabd
dbacz

output

Copy

0

Note

In the first example preprocess moves are as follows: a1:=a1:='b', a3:=a3:='c', a4:=a4:='a' and a5:=a5:='b'. Afterwards, a=a="bbcabba". Then we can obtain equal strings by the following sequence of changes: swap(a2,b2)swap(a2,b2) and swap(a2,a6)swap(a2,a6). There is no way to use fewer than 44preprocess moves before a sequence of changes to make string equal, so the answer in this example is 44.

In the second example no preprocess moves are required. We can use the following sequence of changes to make aa and bb equal: swap(b1,b5)swap(b1,b5), swap(a2,a4)swap(a2,a4).

题意:给你a和b两个字符串,a[i] 和b[i] 可以交换,a[i] 和a[n-1-i] 可以交换, b[i]和b[n-1-i] 可以交换,交换不记数,看a串最少改变多少一个字符,可以和b串相等;

思路:分类讨论 a[i] ,a[n-1-i] ,b[i],b[n-1-i],看看他们的情况;

当讨论时,一定要注意,四个数中有三个不相等的数,说明其中两个是相等的,

有一种是特殊的   a   a

                            b    c

这种情况,需要第一个串, 需要改变两个字符 ,其他三个不相等的情况都是因为改变一个字符,再经交换就可相等

题意上说明了要只能改变第一个串

代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#include<map>
#define Max 100005

char a[Max];
char b[Max];
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		scanf("%s%s",a,b);
		int tt[4];
		int sum = 0;	
		for(int i = 0;i<n/2;i++)
		{
			int sum1 = 1;
			map<int ,int> m;
			m.clear();
			int book[5] = {0};
			tt[0] = a[i] - 'a'+1;
			tt[1] = a[n-1-i] - 'a'+1;
			tt[2] = b[i] - 'a'+1;
			tt[3] = b[n-1-i] - 'a'+1;
			for(int j = 0;j<4;j++)
			{
				if(!m[tt[j]])
				{
					m[tt[j]] = sum1;
					book[sum1] = 1;
					sum1++;
				}
				else
				{
					book[m[tt[j]]]++;
				}
			}
			sum1--;
			
			if(sum1==1||sum1==2&&book[1]==2&&book[2]==2)
				continue;
			else if(sum1==2)
				sum++;
			else if(sum1==3)   // 当这四个字符有三个是不样的,说明其中两个是一样的
							   // 只有 这种情况 a a 这种情况改变两个,其他情况都是改变一个; 
							   //   			b c     因为只能改变 s1 这个字符串; 
												 
			{
				
				if(tt[0]==tt[1])
					sum+=2;
				else sum++;
			}
			else sum+=2;	
		}
		if(n%2&&a[n/2]!=b[n/2])
			sum++;
		printf("%d\n",sum); 
	}
	return 0;
}

 

txt经纬度批量转面要素(附自定义ArcGIS工具箱方法) 当涉及大量txt坐标文件需要转换成面要素的时候,逐步操作工作量较大。本文由需求出发,以ArcGIS10.2为例,采用python脚本自定义ArcGIS工具,实现批量操作的目的。 阅读详情

相关推荐

解决Visual C++2008安装失败,error 1935

重装系统后Visual C++没了,其他都能装上但VC2008会报这个error 1935。鉴于我把网上所有的解决方法排了一遍错,我也不知道是哪一步起效,所以就都放上来了。特别注意:报error 1935的错误原因可能不尽相同,比如我的报错开头为An error occurred,结尾为HRESULT:0x80070005。80070005 拒绝访问通常是权限问题,安装Visual C++无法写入文件夹或注册表(直接跳转第7步)

weixin_44427808的博客 1万+

Codeforces Round #498 (Div. 3) D Two Strings Swaps(思维)

这里链接 好像没什么说的。。直接看代码吧。 解析: #include&lt;bits/stdc++.h&gt; using namespace std; #define ll long long #define pb push_back #define inf 2099999999 #define rep(i,a,b) for(int i=a;i&lt;=b;i++) #define re...

城南的花 180

SPI模式下的SD卡读写,为什么你的数据总出错?详解时序与状态机避坑指南

本文深入探讨SPI模式下SD卡读写数据出错的根本原因,提供时序优化与状态机设计的实战指南。针对时钟周期计数、状态机跳转和忙检测等核心问题,详解命令时序细节、状态机同步策略及高级避坑技巧,帮助开发者提升SD卡在SPI模式下的稳定性和性能。

weixin_30514745的博客 267

Codeforces Round #498 (Div. 3) D - Two Strings Swaps

这是一道毒瘤题,我写博客不是因为题目很好,而是很毒瘤。我错了三次终于过了,每次错了都在想哪里多算了,然后看着输出结果与答案逐渐接近,很刺激,像在解谜,一步步接近真相。事实上是我思维有漏洞,没有考虑完整,所以要一次次修改代码。柳岸花明又一村。 #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;algorithm&gt; #in...

blaze_jack 231

从零到一:Silvaco中跨导曲线的自动化脚本实现

本文详细介绍了如何使用Python脚本在Silvaco中实现跨导曲线(gm曲线)的自动化分析,包括数据加载、跨导计算和结果可视化。通过自动化处理Id-Vg曲线,显著提升半导体器件工程师的工作效率,特别适用于工艺优化和DOE分析。文章还提供了批量处理和关键参数提取的高级技巧,帮助工程师快速掌握Silvaco脚本开发。

nn3456的博客 576

LTC2990电池监控芯片I²C驱动开发与多通道同步采样实践

电池监控是嵌入式电源管理系统的核心环节,其本质依赖高精度模拟信号采集、数字转换与实时状态评估。LTC2990作为集成电压/电流/温度三合一的专用监控IC,通过真差分输入、内置基准和I²C数字接口,显著简化了SOC/SOH估算的硬件链路。其技术价值在于以单芯片替代传统ADC+运放+传感器组合,在宽压(2.7–36 V)、高共模(80 V)场景下保障工业级测量可靠性。典型应用于电动工具、车载BMS、UPS及便携式储能设备的电池健康监测子系统。本文聚焦LTC2990底层驱动实现,涵盖I²C时序约束、寄存器原子读写

weixin_42599558的博客 136

Codeforces Round #498 (Div. 3) D. Two Strings Swaps

题目:传送门 代码如下:   #include &lt;cstdio&gt; #include &lt;cstring&gt; #include &lt;algorithm&gt; #include &lt;iostream&gt; using namespace std; const int maxn=1e5+5; int n; char a[maxn],b[maxn]; int vis[...

zamaochick的博客 174

别再只会用555了!手把手教你用运放和RC电路搭一个50Hz正弦波信号源(附Multisim仿真文件)

本文详细介绍了如何使用运放LM358和RC电路搭建一个精准的50Hz正弦波信号源,涵盖文氏电桥核心原理、单电源供电解决方案、Multisim仿真及实物调试技巧。通过实战指南和优化建议,帮助电子爱好者快速掌握低频信号生成技术,适用于各种测试和校准场景。

weixin_34116482的博客 373

7.17

今天是第二天了,测评姬出了些毛病,今天的rating不算,有喜有悲吧 明天加油! Codeforces Round #498 (Div. 3) A:Adjacent Replacements 题解:奇数位置上的数不变,偶数位置上的数-1; #include<cstdio> #include<algorithm&gt...

TT4191105的博客 141

Matlab GUIDE -- 串口操作

1、首先新建-->应用程序-->GUIDE。 2、绘制一个简单的UI。 3、然后右击“打开串口”图标-->查看回调-->callback,即可打开此图标的回调函数,此回调函数是press button时执行(可按需要选择其他回调)。 4、在回调函数中添加打开串口的代码。 delete(instrfindall); %删除所有串口 s3 = serial('CO

Asgard-X 2843

VideoPose3d:环境搭建+制作自己的视频

论文链接:3D human pose estimation in video with temporal convolutions and semi-supervised training 代码链接:https://github.com/facebookresearch/VideoPose3D 环境搭建:ubuntu20.04+pytorch1.8+cuda10.2+python3.6+anaconda 1.启动anaconda环境 新建环境命令: conda create -n pytorc.

willbetter01的博客 4947

Codeforces Round #498 (Div. 3) (A. B. C. D. F)

  A: Codeforces 1006A. Adjacent Replacements(水题) B:Codeforces 1006B. Polycarp's Practice(思维) C:Codeforces 1006C.Three Parts of the Array(模拟) D:Codeforces 1006D. Two Strings Swaps(思维) F:Codeforces...

Charles_Zaqdt的博客 376

linux系统宝塔服务器temp文件夹里总是被上传病毒php脚本

服务器时不时的会发送短信说你服务器有病毒,找到了这个tmp文件,删除了之后又有了。确实是有很多人就这么无聊,每天都攻击你的服务器。找了很久的原因,网上也提供了一大堆方法,但都是很简陋的答案,具体怎么操作并没有说。没办法只能自己去排查这个问题。从两个角度来考虑,第一是服务器系统问题,比如宝塔的漏洞。但一时半会看不出问题来。只能去排查自己的项目代码。最后了解到代码确实是存在漏洞的。但代码中也确实了很多的校验,为什么会存在漏洞了?这就不得不从上传的过程开始说起。

guiplan 1499

最小二乘法

首先给出公式 最小二乘法的公式 y = a*x+ b; 其中式中N是数据点的个数。注意,以上两式具有相同的分母,∑指逐项加法计算(取和)。∑x指对所有的x值求和,∑y指对所以的y值求和,∑(x^2)指对所有x的平方求和。∑xy指对所有的积xy进行取和计算。应注意,∑xy 与 ∑x*∑y是不相同的(“积的和”与“和的积”是不同的),同样(∑x)^2与∑(x^2)也是不相同的(“和的平方”与...

obsorb_knowledge的博客 9291

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

E. Bus Video System(找刚开始车上,满足的人数,好题,细节多)

E. Bus Video Systemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe busses in Berland are equipped with a video surveillance system. The system ...

obsorb_knowledge的博客 4132

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Seating Arrangement CSU - 1997 (思维题,是否存在n个数的序列,使得相邻啷个数的差绝对值大于d)

Mr. Teacher老师班上一共有n个同学,编号为1到n。 在上课的时候Mr. Teacher要求同学们从左至右按1, 2, …, n的顺序坐成一排,这样每个同学的位置是固定的,谁没来上课就一目了然了。但是时间长了之后,Mr. Teacher发现坐得离得远的同学往往因为交流很少而逐渐变得生疏了,于是他决定重新安排同学们的座位,并且在新的座位安排中,任意两个相邻的同学的编号之差的绝对值都必须大于d...

obsorb_knowledge的博客 1362

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Card Game (First Edition) FZU - 2264 Card Game (Second Edition) FZU - 2265 (数学期望)

Fat brother and Maze are playing a kind of special (hentai) game with some cards. There are N*2 cards in this game for the players to use, this is the card deck. The game goes for N rounds and in each...

obsorb_knowledge的博客 1331

0和5 51Nod - 1433 (为什么整除找出一个最大的整数能整除3或者9,为什么)

小K手中有n张牌,每张牌上有一个一位数的数,这个字数不是0就是5。小K从这些牌在抽出任意张(不能抽0张),排成一行这样就组成了一个数。使得这个数尽可能大,而且可以被90整除。注意:1.这个数没有前导0,2.小K不需要使用所有的牌。Input每个测试数据输入共2行。 第一行给出一个n,表示n张牌。(1&lt;=n&lt;=1000) 第二行给出n个整数a00,a11,a22,…,an−1n−1 (a...

obsorb_knowledge的博客 1286

CodeForces - 892C Pride (n个数,求相邻两个数的最大公约数替换其中一个数,看要操作几次使得n个数全部变成1)

You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denote

obsorb_knowledge的博客 1155

Super-palindrome HDU - 6264 (改变字符,把每个字符串的奇数子串都变成回文的,一定要善于观察)

题目描述You are given a string that is consisted of lowercase English alphabet.You are supposed to change it into a super-palindrome string in minimum steps.You can change one character in string to anoth...

obsorb_knowledge的博客 826

CodeForces - 879B Table Tennis (不要只顾这个数的一边,这个数的前面和后面都的顾)

n people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person fro

obsorb_knowledge的博客 771

2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 (Reversion Count) (一个数和一个数的倒序的差一定是 9的倍数,还有...)

Description:There is a positive integer X, X's reversion count is Y. For example, X=123, Y=321; X=1234, Y=4321. Z=(X-Y)/9, Judge if Z is made up of only one number(0,1,2...9), like Z=11,Z=111,Z=222,do...

obsorb_knowledge的博客 759

CKOJ 1066: 地形编辑器(整个区间加减一个数,多次区间操作,处理端点,但这是二维的,骚操作(有dp思想))

1066: 地形编辑器时间限制: 1 Sec  内存限制: 128 MB提交: 32  解决: 4[提交][状态][讨论版]题目描述zdw很喜欢玩红警, 他经常制作一些奇奇怪怪的红警地图当他制作地图的时候, 经常需要用到地形编辑器zdw可以用这个编辑器将地图上的某个区域的高度改变x来创造地形一次显然是不够的, 而经过若干次的操作后, 地图上将会出现各种山脉和峡谷现给出zdw的所有操作, 求这些操作...

obsorb_knowledge的博客 632

Codeforces Round #511 (Div. 2) C. Enlarge GCD(消掉最少的数,让所有数的最大公约数变大)

C. Enlarge GCD time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mr. F has nn positive integers, a1,a2,…,ana1,a2,…,an. He thinks th...

obsorb_knowledge的博客 618

HDU - 6025 Coprime Sequence(给出一行数,去掉其中一个数,求这行数的最大的最大公约数(gcd)))

Do you know what is called ``Coprime Sequence''? That is a sequence consists of nnpositive integers, and the GCD (Greatest Common Divisor) of them is equal to 1.  ``Coprime Sequence'' is easy to fi

obsorb_knowledge的博客 598

CodeForces - 931D Peculiar apple-tree(模拟树的结构,一定要从树根到树枝搜索,因为是从树根发叉的,树根为一个点,树枝为多个点)

In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence n...

obsorb_knowledge的博客 587
上一篇: 2018 “百度之星”程序设计大赛 - 初赛(A)度度熊学队列 list双向链表
下一篇: 石子合并问题--直线版 HRBUST - 1818 (区间dp入门)
obsorb_knowledge
博客等级 码龄9年 38粉丝 213原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值