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("");
}
Codeforces Round #550 (Div. 3)E. Median String的更多相关文章
- Codeforces Round #550 (Div. 3) E. Median String (模拟)
Median String time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #550 (Div. 3) E. Median String (思维,模拟)
题意:给你两个字符串\(s\)和\(t\),保证\(t\)的字典序大于\(s\),求他们字典序中间的字符串. 题解:我们假设题目给的不是字符串,而是两个10禁止的正整数,那么输出他们之间的数只要把他两 ...
- 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String
题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...
- CodeForces Round #550 Div.3
http://codeforces.com/contest/1144 A. Diverse Strings A string is called diverse if it contains cons ...
- Codeforces Round #327 (Div. 2) C. Median Smoothing 找规律
C. Median Smoothing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/p ...
- Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)
题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cs ...
- Codeforces Round #303 (Div. 2) B. Equidistant String 水题
B. Equidistant String Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/54 ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- Codeforces Round #604 (Div. 2) A. Beautiful String
链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...
随机推荐
- HDU 4514
真是神奇,G++TLE,C++500MS... 判环有一个图论知识就是,m>=n时必有环.如果以m的范围建图,会MLE. 然后,利用拓扑排序再来判定是否有环,因为有些景点可能是孤立的.同时,在拓 ...
- maven install:install出现的错误提示
maven install:install出现的错误提示 [INFO] --- maven-install-plugin:2.4:install (default-cli) @ maven028 -- ...
- eclipse 执行MapReduce程序错误异常汇总(解决Map not fount)
错误一: Error: java.lang.RuntimeException: java.lang.ClassNotFoundException: Class wordCount.wordCount$ ...
- VMware Workstation 集群仲裁磁盘和数据共享磁盘的创建
近期项目须要对SQL Server建立集群服务,多个SQL Server数据库建立集群服务,对外提供唯一的URL訪问地址.当主节点断电.断网后,通过心跳线将消息传递到备用节点.备用节点在3秒内接管数据 ...
- Instagram的Material Design概念设计文章分享
近期開始研究最新的Android 5 Material Design,一加氢OS公布后,非常快就有一大批支持Android5原生风格的手机出来了,你的App还是UI帮设计的吗?该考虑升级到 Mater ...
- bzoj 1191 [ HNOI 2006 ] 超级英雄Hero —— 二分图匹配
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1191 就是二分图匹配的裸题: 注意题目要求是第一次匹配失败就退出!没仔细看题差点丢失1A. ...
- K-means (PRML) in C++
原始数据 #include <iostream>#include <fstream>#include <sstream>#include <vector> ...
- sublime如何汉化
1.将sublime安装文件夹里面的defavlut.sublime-package这个文件zip解压. 2.然后查找到sublime-menu文件. 3.打开文件将json里面的caption里面的 ...
- Django day08 多表操作 (四) 一对多, 多对多连续跨表查询
一对多 # 基于双下划线的一对多查询 # 查询出版社为上海出版社的所有图书 # ret = Publish.objects.filter(name='上海出版社').values('book__nam ...
- C# 取两位小数
double s=0.55555;result=s.ToString("#0.00");//点后面几个0就保留几位 如果要四舍五入的话,用这个double dbdata = 0.5 ...