• 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("");
    }
    

      

  • 相关阅读:
    构造函数与析构函数2
    构造函数与析构函数(其中有两点值得学习)
    构造函数含有含默认值的参数
    A simple stack
    指针与const
    构造函数与析构函数
    构造函数的创建
    类的定义
    程序的堆与栈(转载)
    OpenStack 安装:glance 安装
  • 原文地址:https://www.cnblogs.com/HazelNut/p/10634221.html
Copyright © 2020-2023  润新知