首页 技术 正文
技术 2022年11月14日
0 收藏 611 点赞 2,165 浏览 2618 个字

Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.

To settle this problem, they’ve decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.

For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :

Initially, the company name is ???.

Oleg replaces the second question mark with ‘i’. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.

Igor replaces the third question mark with ‘o’. The company name becomes ?io. The set of letters Igor have now is {i, m}.

Finally, Oleg replaces the first question mark with ‘o’. The company name becomes oio. The set of letters Oleg have now is {i}.

In the end, the company name is oio.

Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?

A string s = s1s2sm is called lexicographically smaller than a string t = t1t2tm(where s ≠ t) if si < ti where i is the smallest index such that si ≠ ti. (so sj = tjfor all j < i)

Input

The first line of input contains a string s of length n (1 ≤ n ≤ 3·105). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.

The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.

Output

The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.

Examples

Input

tinkoff
zscoder

Output

fzfsirk

Input

xxxxxx
xxxxxx

Output

xxxxxx

Input

ioi
imo

Output

ioi

题意:A,B都有N个字符,A和B轮流贡献一个字符,A想组成的字典序越小,B想组成的字典序越大。

思路:A肯定是贡献出最小的(N+1)/2个字符,B贡献出最大的N/2个字符。 错误思路是A从小到大贡献字符,B从大到小贡献字符,但是会出现错误,

比如A=cbxy,B=aaaa,错误解=baca,正解=abac。正确的贪心策略应该是:对A,如果最小值小于B的最大值,那么把最小值填到前面,否则把最大值填到最后。B同理。

#include<bits/stdc++.h>
using namespace std;
const int maxn=;
char a[maxn],b[maxn],ans[maxn];
int main()
{
int N,L,R,h1,t1,h2,t2;
scanf("%s%s",a+,b+); N=strlen(a+);
sort(a+,a+N+); sort(b+,b+N+);
L=; R=N; h1=; t1=(N+)/; h2=N; t2=N-N/+;
while(L<=R){
if(a[h1]<b[h2]) ans[L++]=a[h1++];
else ans[R--]=a[t1--];
if(L>R) break;
if(b[h2]>a[h1]) ans[L++]=b[h2--];
else ans[R--]=b[t2++];
}
for(int i=;i<=N;i++) printf("%c",ans[i]);
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,493
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,133
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297