Two Strings Swaps 【CodeForces - 1006D】

Shell数学计算(算术运算,加减乘除运算) 声明: 本篇博客的学习途径主要为以下网站和课堂讲解,发博客目的仅为学习使用,在该博客的基础上做了一定程序的简略和修改。 参考博客 : 原文链接:http://c.biancheng.net/shell/ Shell数学计算Shell数学计算数学计算命令对整数进行数学运算: (()) / let / $[] /exprShell (())Shell let命令bc命令:一款数学计算器在 Shell 中使用 bc 计算器 Shell数学计算 默认情况下,Shell 不会直接进行算术运算,而是把+两边的数据(数 阅读详情

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

7
abacaba
bacabaa

output

4

input

5
zcabd
dbacz

output

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-i+1],三是交换b[i]和b[n-i+1],这三个操作都是不计步数的,然后问最少还需要多少步可以让a串等于b串。

代码:

#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;

int n;
char s[100010],t[100010];

int main()
{
    scanf("%d",&n);
    scanf("%s%s",s,t);
    int k=0;
    for(int i=0; i<n/2; i++)
    {
        map<char,int>v;
        v[s[i]]++;
        v[t[i]]++;
        v[s[n-i-1]]++;
        v[t[n-i-1]]++;
        if(v.size()>=2)
        {
            if(v.size()==2)
            {
                if(v[s[i]]!=2)
                    k++;
            }
            else if(v.size()==3)
            {
                if(s[i]==s[n-i-1])
                    k+=2;
                else
                    k++;
            }
            else
                k+=2;
        }
    }
    if(n%2)
        if(s[n/2]!=t[n/2])
            k++;
    printf("%d\n",k);
}

 

SAPGUI excel 导出时遇到的运行时错误:STRING_SIZE_TOO_LARGE 当报表导出需求远超单一 XLSX 文件的物理承载力时,与其在 SAPGUI 中硬拼 2 GB 限制,不如把分页、过滤、流式写入作为设计前提。掌握 ABAP2XLSX 或 CSV + Power Query 等工具链,既能满足审计合规,又能让应用服务器远离的噩梦。祝你在下一次导出海量数据时,既高效又优雅。 阅读详情

相关推荐

微带天线理论学习笔记(1)

微带天线的概念是由Deschamps于1953年提出来的,它是在一块厚度远小于工作波长的介质基片的一面敷以金属辐射片、一面全部敷以金属薄层作接地板而成。辐射片可以根据不同的要求设计成各种形状。微带天线具有质量轻、体积小和易于制造等优点,广泛应用于个人无线通信中。

qq_36521926的博客 6226

CF 1295C Obtain The String

题目链接:https://codeforces.com/problemset/problem/1295/C You are given two strings s and t consisting of lowercase Latin letters. Also you have a string z which is initially empty. You want string z to b...

桃夭丶的博客 423

Linux下Linpack测试GPU和CPU性能

前面的文章已经介绍了如何搭建Linpack环境:https://blog.youkuaiyun.com/liu_feng_zi_/article/details/107429720 接下来说明如何使用 一、编写运行脚本: 新建文件:run_linpack.sh,内容如下: export HPL_DIR =/root/LHC/Linpack/hpl-2.0_FERMI_v15 export MKL_NUM_THREADS=6 export OMP_NUM_THREADS=6 export MKL_DYNAMI.

liu_feng_zi_的专栏 4633

Codeforces1409 F. Subsequences of Length Two(DP)

You are given two strings ???? and ???? consisting of lowercase Latin letters. The length of ???? is 2 (i.e. this string consists only of two characters). In one move, you can choose any character of ???? and replace it with any lowercase Latin letter. Mor

tomjobs的博客 650

新版本大疆智图4.5 永久许可摄影测量建模软件

大疆智图支持常见格式的成果输出,包括 TIFF 正射影像和高程模型、LAS 格式点云,以及 B3DM、OSGB、OBJ 等六种常用格式的三维模型,还包括 DXF 和 SHP 等格式的等高线。大疆智图 DJI Terra是领先的三维重建软件,提供先进的技术和简单的操作,一站式解决方案,从航线规划到数据的获取,以及模型重建、数据分析等都提供独一无二的支持,优化项目工程,提供自动化优势,获得更有效智能的决策和行动,最终用户可以获得理想的结果,减轻工作压力,提高作业效率。质量报告和剖面查看功能有助于分析点云质量。

qq_62821232的博客 6893

初学者入门机器学习 (ML)的推荐教程

了解基本的机器学习概念并不难。有大量免费的在线博客文章、视频和编码教程可以引导您了解基础知识——从介绍性内容到常见应用程序,再到算法和应用技能。这篇文章总结了一些用于介绍 ML 的最佳免费选项。它按逻辑顺序排列,每个概念都建立在上一个概念的基础上。

u010542847的博客 4617

C. Obtain The String

链接:https://codeforces.com/contest/1295/problem/C You are given two stringsssandttconsisting of lowercase Latin letters. Also you have a stringzzwhich is initially empty. You want stringzzto b...

Luoriliming的博客 699

损失函数大汇总(八)(IoU Loss附公式推导与代码)

本文详细介绍了IoU Loss及其在图像分割中的应用。IoU(交并比)是衡量预测区域与真实区域重叠程度的指标,IoU Loss定义为1-IoU,直接优化区域重叠质量。文章推导了IoU的数学表达式和梯度计算,分析了其函数特性:全局耦合梯度、对漏检误检的双重惩罚、适合类别不平衡任务。与Dice Loss相比,IoU更强调覆盖质量而非相似度。实际应用中IoU Loss常与BCE组合使用,前者保证训练稳定性,后者优化整体区域质量。文章还提供了IoU Loss的代码实现,适用于二值分割、小目标提取等场景,特别当任务评

悦学共鸣,温柔以待,汇聚光芒,共同成长 414

Beautiful Substrings【枚举】

题目描述:原题链接 You are given two strings a and b consisting of lowercase English letters. A beautiful substring is defined as a substring of any length of string b such that the first and last letters of it are the same as the first and last letters of any subs

weixin_45619734的博客 190

8.DJI-PSDK:一站式项目功能开发总结(空中气象站项目/激光甲烷检测项目)

本文将以一篇文章的幅度快速完成: 项目一:空中气象站项目; 项目二:激光甲烷项目; 项目所使用的PSDK来源于第0章节末尾的百度网盘;解压:Payload-SDK-3.8.zip代码所在目录:双击打开: 修改打印串口和相关波特率,我们修改如下: 进行相关编译选项配置如下: :

哒宰的博客 294

手把手教你学Simulink——基于核能发电系统的场景实例:核电站汽轮机与发电机协调控制仿真

在核电机组中,汽轮机-发电机系统是将核能最终转化为电能的关键环节。与火电机组不同,核反应堆的热惯性大、功率调节慢,因此汽轮机的控制策略需与反应堆特性相匹配,实现安全、稳定、高效的能量转换。维持发电机输出功率/频率稳定(响应电网调度)调节汽轮机进汽压力(匹配一回路蒸汽供应)实现“堆-机协调控制”保障机组在启停、变负荷、甩负荷等工况下的安全性本教程将带你使用构建一个核电站汽轮机与发电机协调控制系统汽轮机调速系统(调门控制)建模发电机与电网接口建模(同步机)

MHD0815的博客 212

CodeForces 1295C Obtain The String

题目描述: You are given two strings s and t consisting of lowercase Latin letters. Also you have a string z which is initially empty. You want string z to be equal to string t. You can perform the following operation to achieve this: append any subseqFuence of

weixin_43023396的博客 256

Mastercam软件二次开发:使用C#进行Mastercam二次开发

C#(发音为“C Sharp”)是一种现代、面向对象的编程语言,由微软开发,首次发布于2000年。它结合了C和C++的强大功能,同时引入了Java的垃圾回收机制,使得C#在开发效率和运行性能之间找到了一个良好的平衡点。C#的设计目标是提高开发者的生产力,它支持多种编程范式,包括面向对象、泛型、委托和事件等,这使得它成为开发Windows应用程序、Web应用程序、游戏(尤其是使用Unity引擎)和企业级应用的理想选择。

kkchenjj的博客 2214

【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; cons...

AWCXV 129

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

Two Strings Swaps CodeForces - 1006D

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 followi...

Qtt110的博客 249

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

Codeforces 1006D - Two Strings Swaps

链接:Codeforces 1006D - Two Strings Swaps 大意:给你两个长度为n的字符串a,b,你可以进行下列三种操作:1.调换a,b相同位置的字符;2.调换a串中对称位置的字符;3.调换b串中对称位置的字符。在进行这三种操作之前,你可以进行预处理的操作,即对a串中某些位置的字符串进行替换。求至少进行多少次预处理之后,可以通过上述三种操作使得a串等于b串。 思路:思维题,...

淡泊明志,宁静致远 299

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

CodeForces - 1006D Two Strings Swaps

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 follo...

GJLfly的博客 383

codeforces 解题报告 1006D. Two Strings Swaps 分类讨论

http://codeforces.com/contest/1006/problem/D 解题思路: 1.按照题目要求对字符串进行分割,分组讨论,每组得到四个字符,例如:上面串的第一个和最后一个,下面串的第一个和最后一个。 2.分类讨论: 一组字符中存在两对相等字符的情况则不需要替换操作 一组字符中上面两个与下面两个至少存在一对相等字符的情况,那么只需要修改上面的一个就能获得...

三生锁链 571

【分类讨论】CodeForces - 1006D·Two Strings Swaps

题目 题目大意 分析 代码 题目 传送门 题目大意 给你两个字符串 aaa 和 bbb,长度均为nnn,你可以对两个字符串进行如下操作(1≤i≤n1≤i≤n1\leq i\leq n): 交换字符 aiaia_i 和 an−i+1an−i+1a_{n-i+1} 交换字符 aiaia_i 和 bibib_i 交换字符 bibib_i 和 bn−i+1bn−i+1b_{...

ixRic 1401

CodeForces - 1006D Two Strings Swaps

题意:

Yishui_lovely 247

Codeforces 1006D. Two Strings Swaps(思维)

  题目链接:http://codeforces.com/contest/1006/problem/D        题意是给了两个字符串a和b,然后可以对这两个字符串有三种操作来使这两个字符串相等,一是交换a[i]和b[i],二是交换a[i]和a[n-i+1],三是交换b[i]和b[n-i+1],这三个操作都是不计步数的,然后问最少还需要多少步可以让a串等于b串。        思路就是模...

Charles_Zaqdt的博客 519

F - Two Strings Swaps CodeForces - 1006D

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 followi...

lihuanz的博客 206

CodeForces1006D-Two Strings Swaps

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 stringsaaandbbco...

weixin_30521161的博客 124

Codeforces ~ 1006D ~ Two Strings Swaps(思维)

题意 两个长度为n的字符串a,b。先将a改变一些字符,然后通过任意次交换操作使a==b,问a最少需要改变几个字符? 字符串下标为从1到n,①swap(a[i],b[i])②swap(a[i],a[n-i+1])③swap(b[i],b[n-i+1])   思路 其实情况并不多,仔细考虑一下就好了。 a[l],a[r]表示a[i]和a[n-i+1],b[l]和b[r]同理。 每次看四个...

张松超的博客 613

Two Strings Swaps

Two Strings Swaps CodeForces - 1006D You are given two strings a and b consisting of lowercase English letters, both of length n. The characters of both strings have indices from 1 to n, inclusive. Yo...

weixin_43895356的博客 469
上一篇: Bridging signals 【POJ - 1631】
下一篇: 饭卡 [ HDU - 2546 ]
Daisy's一乐景三
博客等级 码龄8年 2粉丝 56原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值