Median String CodeForces - 1144E
You are given two strings ss and tt, both consisting of exactly kk lowercase Latin letters, ss is lexicographically less than tt.
Let's consider list of all strings consisting of exactly kk lowercase Latin letters, lexicographically not less than ss and not greater than tt (including ss and tt) in lexicographical order. For example, for k=2k=2, s=s="az" and t=t="bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"].
Your task is to print the median (the middle element) of this list. For the example above this will be "bc".
It is guaranteed that there is an odd number of strings lexicographically not less than ss and not greater than tt.
Input
The first line of the input contains one integer kk (1≤k≤2⋅1051≤k≤2⋅105) — the length of strings.
The second line of the input contains one string ss consisting of exactly kk lowercase Latin letters.
The third line of the input contains one string tt consisting of exactly kk lowercase Latin letters.
It is guaranteed that ss is lexicographically less than tt.
It is guaranteed that there is an odd number of strings lexicographically not less than ss and not greater than tt.
Output
Print one string consisting exactly of kk lowercase Latin letters — the median (the middle element) of list of strings of length kk lexicographically not less than ss and not greater than tt.
Examples
2
az
bf
bc
5
afogk
asdji
alvuw
6
nijfvj
tvqhwp
qoztvz 题意:给你两个只含有小写字母的字符串, s和t,保证s的字典序比t小。把s和t看成一个26进制的数,让你输出这两个数的中位数。 思路:首先把两个字符串的每一个位上的数值加起来,然后向前进位。
然后从头开始遍历加起来的那个数值,如果数值为偶数,那么中位数的这一位就是数值/2,如果是奇数,那么中位数的这一位是/2且向下取整。
并把那个多余的一加到下一位中,(注意上一位的1到下一位是26),最后输出答案即可。 *(主要是通过咱们熟悉的十进制来找到转换的规律,然后处理。)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int a[maxn];
int b[maxn];
int main()
{
// freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
// freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
gbtb;
// repd(i,0,25)
// {
// cout<<(char)('a'+i)<<" ";
// }
string xia;
string shang;
int k;
cin>>k>>xia>>shang;
for(int i=k-;i>=;i--)
{
// a[i-1]+=(shang[i]+xia[i]-'a'-'a')/26;
a[i]+=(shang[i]+xia[i]-'a'-'a');
}
for(int i=k-;i>;i--)
{
a[i-]+=a[i]/;
a[i]%=;
}
// repd(i,0,k)
// {
// db(a[i]);
// }
for (int i = ; i < k; ++i)
{
if(a[i]&)
{
a[i+]+=;;
b[i]=a[i]/;
}else
{
b[i]=a[i]/;
}
}
for (int i = ; i < k; ++i)
{
cout<<(char)(b[i]+'a');
/* code */
}
cout<<endl;
return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}
Median String CodeForces - 1144E的更多相关文章
- 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 ...
- Minimal string CodeForces - 797C
Minimal string CodeForces - 797C 题意:有一个字符串s和空串t和u,每次操作可以将s的第一个字符取出并删除然后放到t的最后,或者将t的最后一个字符取出并删除然后放到u的 ...
- E. Median String 解析(思維、大數運算)
Codeforce 1144 E. Median String 解析(思維.大數運算) 今天我們來看看CF1144E 題目連結 題目 給你兩個長度為\(k\)的字串\(s\)和\(t\),求字典序排序 ...
- Codeforces 1144 E. Median String
原题链接:https://codeforces.com/problemset/problem/1144/E tag:字符串模拟,大整数. 题意:给定两个字符串,求字典序中间串. 思路:可以把这个题当做 ...
- Codeforces Round #550 (Div. 3)E. Median String
把字符串看作是26进制的数,从后往前翻译,那么就可以把两个串变成对应的26进制的数字,那么只要把两个数加起来除以二就得到中间的串对应的数了,同理再转化回来就行了.但是这样会有一个问题就是串的长度有2e ...
- Codeforces Round #550 (Div. 3) E. Median String (思维,模拟)
题意:给你两个字符串\(s\)和\(t\),保证\(t\)的字典序大于\(s\),求他们字典序中间的字符串. 题解:我们假设题目给的不是字符串,而是两个10禁止的正整数,那么输出他们之间的数只要把他两 ...
- D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)
http://codeforces.com/contest/862/problem/D 交互题 fflush(stdout) 调试: 先行给出结果,函数代替输入 #include <cstdio ...
- You Are Given a Decimal String... CodeForces - 1202B [简单dp][补题]
补一下codeforces前天教育场的题.当时只A了一道题. 大致题意: 定义一个x - y - counter :是一个加法计数器.初始值为0,之后可以任意选择+x或者+y而我们由每次累加结果的最后 ...
- Check the string CodeForces - 960A
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend ...
随机推荐
- Python 中if __name__ == '__main__': 的作用和原理
转自https://blog.csdn.net/weixin_42660771/article/details/84035153 1.代码的功能 一个python的文件有两种使用的方法,第一是直接作为 ...
- Sql查询今天、本周和本月的记录(时间字段为时间戳)
工作中遇到的问题,小结一下 查询今日添加的记录: select * from [表名] where datediff(day,CONVERT(VARCHAR(20),DATEADD(SECOND,[时 ...
- Python3 Selenium多窗口切换
Python3 Selenium多窗口切换 以腾讯网(http://www.qq.com/)为例,打开腾讯网,点击新闻,打开腾讯新闻,点击新闻中第一个新闻链接. 在WebDriver中封装了获取当前窗 ...
- 025k个一组翻转链表
#include "000库函数.h" struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), n ...
- Java JDK与JRE
JDK与JRE JDK(Java Development Kit):Java开发工具包.包含JRE中的所有内容,以及用于开发小应用程序和应用程序的编译器和调试器等工具. JRE(Java Runtim ...
- Kafka 0.11新功能介绍:空消费组延迟rebalance
Kafka 0.11新功能介绍:空消费组延迟rebalance 在0.11之前的版本中,多个consumer实例加入到一个空消费组将导致多次的rebalance,这是由于每个consumer inst ...
- 阿里云ECS配置踩坑之路
1.利用shadowsocks配置SVN(用于软件部署环境) 2.安全组设置 3.FTP搭建 https://www.cnblogs.com/hexige/p/7809481.html
- 学习Ant Design Pro的一点心得
1.控制反转(Inversion of Control)是一种「思想」,依赖注入(Dependency Injection)则是这一思想的一种具体「实现方式」 2.react 要注意全局 id相同 3 ...
- react中使用Ajax请求(axios,Fetch)
React本身只关注于界面, 并不包含发送ajax请求的代码,前端应用需要通过ajax请求与后台进行交互(json数据),可以使用集成第三方ajax库(或自己封装) 常用的ajax请求库 jQuery ...
- 如何在excel单元格中插入图片批注
在excel单元格中插入图片批注的方法: 1.选定要插入图片的单元格,然后右键选择插入批注. 2.然后会插入一个批注框,为了不影响图片效果,可以将批注文字都删除.然后鼠标移动到批注框边角再右键. 3. ...