zoukankan      html  css  js  c++  java
  • Codeforces Round #550 (Div. 3)E. Median String

    把字符串看作是26进制的数,从后往前翻译,那么就可以把两个串变成对应的26进制的数字,那么只要把两个数加起来除以二就得到中间的串对应的数了,同理再转化回来就行了。
    但是这样会有一个问题就是串的长度有2e5,26的2e5次方显然不可求,所以需要对每一位进行手动的加和运算。
    对于两个串,我们假设a串从后往前的每一位对应的数值为a0, a1, a2...,b串从后往前的每一位对应的数值为b0, b1, b2...对于进制加法,有

    扔一下垃圾代码:

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <set>
    #include <map>
    #define INF 0x3f3f3f3f
    #define ll long long
    #define lowbit(x) (x&(-x))
    #define PI acos(-1)
    #define ms(x,y) memset(x, y, sizeof(x))
    using namespace std;
    
    const int maxn = 2e5+7;
    char a[maxn], b[maxn];
    
    int ans[maxn];
    
    int main()
    {
        int n;
        scanf("%d", &n);
        scanf("%s%s", a, b);
        
        for(int i=n-1;i>=0;i--)
        {
            int ta = a[i] - 'a';
            int tb = b[i] - 'a';
            ans[i] = ta + tb;
            
            if(ans[i]&1)
            {
                ans[i+1] += 13;
                ans[i] = (ans[i] - 1) / 2;
                ans[i] += ans[i+1] / 26;
                ans[i+1] %= 26;
            }
            else ans[i] = ans[i] / 2;
        }
        
    
        
        for(int i=0;i<n;i++) printf("%c", 'a' + ans[i]); puts("");
    }
    

      

  • 相关阅读:
    zabbix监控docker
    Ubuntu下Zabbix结合percona监控mysql数据
    centos7安装ftp
    Ubuntu 16.04 搭建 ELK
    ubuntu网卡配置及安装ssh服务
    CentOS7.5二进制安装MySQL-5.6.40
    生产环境MySQL数据库集群MHA上线实施方案
    Mysql主从复制
    GIt+jenkins代码自动上线
    虚拟机网卡丢失解决方法
  • 原文地址:https://www.cnblogs.com/HazelNut/p/10634221.html
Copyright © 2011-2022 走看看