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 4504
直接DP求组合数即可. #include <iostream> #include <cstdio> #include <algorithm> #include &l ...
- 最小生成树模板(poj3625)
Building Roads Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9360 Accepted: 2690 De ...
- mysql之left join、right join、inner join的区别
left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录 inner join(等值连接) ...
- buaa 1033 Easy Problem(三分)(简单)
Easy Problem 时间限制:1000 ms | 内存限制:65536 KB 描写叙述 In this problem, you're to calculate the distance b ...
- WebView 用法总结
1.AndroidManifest.xml中必须使用许可"android.permission.INTERNET",否则会出 Web page not available 错误. ...
- 【辨异】—— 可见 vs. 不可见
1. 常见对比 物理可见,逻辑不可见: 效果可见: 对于一个文档,字符.图形可见,行.列.页呀等结构化的元素,不可见,它们各是一种逻辑组织与安排: 观念(思维方式,看待事情的方式)是不可见的,但行为是 ...
- bzoj4197 [Noi2015]寿司晚宴——状压DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4197 首先,两个人选的数都互质可以看作是一个人选了一个数,就相当于选了一个质因数集合,另一个 ...
- 当Shell遇上了Node.js(转载)
转载:http://developer.51cto.com/art/201202/315066.htm 好吧,我承认,这个标题有点暧昧的基情,但是希望下文的内部能给不熟悉或不喜欢Shell或WIN平台 ...
- spark作业运行过程之--DAGScheduler
DAGScheduler--stage划分和创建以及stage的提交 本篇,我会从一次spark作业的运行为切入点,将spark运行过程中涉及到的各个步骤,包括DAG图的划分,任务集的创建,资源分配, ...
- Oracle_exp/expdp备份
目录索引 1.exp和expdp的区别 2.expdp导出数据库流程 一.↓↓exp和expdp的区别↓↓ 1.exp和expdp最明显的区别就是导出速度的不同.expdp导出是并行导出(如果把exp ...