• 题意:给你两个长度相同的字符串\(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 (思维)的更多相关文章

  1. Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)

    Codeforces Round #521 (Div. 3)  E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...

  2. Codeforces Round #498 (Div. 3) 简要题解

    [比赛链接] https://codeforces.com/contest/1006 [题解] Problem A. Adjacent Replacements        [算法] 将序列中的所有 ...

  3. Codeforces Round #313 (Div. 1) B. Equivalent Strings

    Equivalent Strings Problem's Link: http://codeforces.com/contest/559/problem/B Mean: 给定两个等长串s1,s2,判断 ...

  4. Codeforces Round #313 (Div. 2) D. Equivalent Strings

    D. Equivalent Strings Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/ ...

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

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

  7. Codeforces Round #302 (Div. 1) C - Remembering Strings 状压dp

    C - Remembering Strings 思路:最关键的一点是字符的个数比串的个数多. 然后就能状压啦. #include<bits/stdc++.h> #define LL lon ...

  8. (原创)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 ...

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

随机推荐

  1. C++ 中的 inline 详解

    inline:是一个关键词,放在一个函数前面,说明这个函数是inline函数. inline函数是什么?inline有什么作用? 为了解答这个问题,我们首先要知道编译器是如何为我们工作的. 先看一段代 ...

  2. scaffoldingTools

    脚手架工具 脚手架工具概要(前端工程化的发起者) 脚手架的本质作用:创建项目基础架构.提供项目规范和约定 相同的组织结构 相同的开发规范 相同的模块依赖 相同的工具配置 相同的基础代码 举例:IDE创 ...

  3. Spring Cloud微服务Sentinel+Apollo限流、熔断实战总结

    在Spring Cloud微服务体系中,由于限流熔断组件Hystrix开源版本不在维护,因此国内不少有类似需求的公司已经将眼光转向阿里开源的Sentinel框架.而以下要介绍的正是作者最近两个月的真实 ...

  4. 文件监控性能问题【BUG】

    文件监控性能问题[BUG] 背景:JAVA写了一个文件夹目录监控的程序,使用的是org.apache.commons.io.monitor 包,项目稳定运行了一个月,现场反馈,文件夹数据处理越来越慢, ...

  5. Centos7.4 小白式安装(初学)

    虚拟机安装Centos7.4系统 适用人群(初学者) 下载Centos7.4镜像 https://pan.baidu.com/s/1NtjfdHV3OWAvfDj5vrR7HQ  提取码:hzzw 虚 ...

  6. 微服务网关1-Spring Cloud Gateway简介

    一.网关基本概念 1.API网关介绍 ​ API 网关出现的原因是微服务架构的出现,不同的微服务一般会有不同的网络地址,而外部客户端可能需要调用多个服务的接口才能完成一个业务需求,如果让客户端直接与各 ...

  7. 转 12 jmeter性能测试实战--web程序

    12 jmeter性能测试实战--web程序   项目背景 项目:XX网站环境:Windows需求:并发登录的性能测试场景:1s增加2个线程,运行2000次(线程数20,Ramp-Up seconds ...

  8. mysql的安装使用及其用户管理

    mysql的安装使用及其用户管理   一.mariadb安装 搭建yum源 [mariadb] name = MariaDB baseurl = http://mirrors.ustc.edu.cn/ ...

  9. windows10复制粘贴键突然失效无法复制粘贴的最简单办法

    报了学习班,打开了VCE的加密文档 今天复制粘贴键突然失效 在网上捣鼓了好多方法都不行最后发现看看你有没有在用加密文件,也就是网课类的文档和视频.有就把它关了关了就好了

  10. 【LinuxShell】free 命令详解

    前言 free命令用来显示Linux中的内存使用信息,包括空闲的.已用的物理内存,swap内存,及被内核使用的buffer.在Linux系统监控的工具中,free命令是最经常使用的命令之一. 命令格式 ...