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 cin 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 = s1s2...sm is called lexicographically smaller than a string t = t1t2...tm(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

题意:甲乙两人各持有一个长度均为n的字符串,轮着向一个新的长也为n的字符串里放字符,甲先行。
甲每一步都试图让字符串按字典序最小化,乙每一步都试图让字符串按字典序最大化。问最后这新字符串是什么。
 #include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-6
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define fuck(x) cout<<"["<<x<<"]"<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("DATA.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
#pragma comment (linker,"/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x7fffffff;
const int mod = 1e9 + ;
const int maxn = 4e5 + ;
int n, k, a[maxn], ans[maxn];
char s1[maxn], s2[maxn], s3[maxn];
int cmp(char x, char y) {
return x > y;
}
int main() {
scanf("%s%s", s1, s2);
int n = strlen(s1), k = ;
sort(s1, s1 + n);
sort(s2, s2 + n, cmp);
int i = , j = , ed1 = (n - ) / , ed2 = (n - ) / , L = , R = n - ;
if (n & ) ed2--;
while(k < n) {
if (k % == ) {
if (s1[i] >= s2[j]) s3[R--] = s1[ed1--];
else s3[L++] = s1[i++];
} else {
if (s2[j] <= s1[i]) s3[R--] = s2[ed2--];
else s3[L++] = s2[j++];
}
k++;
}
s3[n] = '\0';
printf("%s\n", s3);
return ;
}

Naming Company CodeForces - 794C的更多相关文章

  1. Naming Company CodeForces - 794C (博弈,构造)

    Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little thi ...

  2. [刷题]Codeforces 794C - Naming Company

    http://codeforces.com/contest/794/problem/C Description Oleg the client and Igor the analyst are goo ...

  3. CodeForces - 794C:Naming Company(博弈&简单贪心)

    Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little thi ...

  4. 【codeforces 794C】Naming Company

    [题目链接]:http://codeforces.com/contest/794/problem/C [题意] 有n个位置; 两个人; 每个人都有n个字符组成的集合s1,s2(可以有重复元素); 然后 ...

  5. Codeforces Round #414 C. Naming Company

    http://codeforces.com/contest/794/problem/C 题意: 有两个人要为公司起名字,每个人手中都有n个字符,现在要取一个n个字符长度的公司名.两人轮流取名,每次选择 ...

  6. codeforces 794 C. Naming Company(贪心)

    题目链接:http://codeforces.com/contest/794/problem/C 题意:有两个人每个人都有一个长度为n的字符串,两人轮流拿出一个字符串,放在一个长度为n的字符串的指定位 ...

  7. 【贪心】【multiset】Tinkoff Challenge - Final Round (Codeforces Round #414, rated, Div. 1 + Div. 2) C. Naming Company

    考虑两个人,先把各自的集合排个序,丢掉一半,因为比较劣的那一半一定用不到. 然后贪心地放,只有两种决策,要么把一个最优的放在开头,要么把一个最劣的放在结尾. 如果我的最优的比对方所有的都劣(或等于), ...

  8. 【贪心+博弈】C. Naming Company

    http://codeforces.com/contest/794/problem/C 题意:A,B两人各有长度为n的字符串,轮流向空字符串C中放字母,A尽可能让字符串字典序小,B尽可能让字符串字典序 ...

  9. Tinkoff Challenge - Final Round (Codeforces Round #414, rated, Div. 1 + Div. 2) 【ABC】

    老年人题解,语言python3 A - Bank Robbery 题意:给你ABC,以及n个数,问你在(B,C)之间的数有多少个. 题解:对于每个数判断一下就好了嘛 x,y,z = map(int,i ...

随机推荐

  1. 一个五位数ABCDE乘以9,得到EDCBA,求此五位数

    此题是面试时某面试官突然抛出的,要求逻辑分析推导,不许编码,5分钟时间算出来最终结果,当然,最终没有完全推算出来 下面是编码实现 #一个五位数ABCDE*9=EDCBA,求此数 for a in ra ...

  2. docker容器学习笔记

    docker是通过内核虚拟化技术来提供容器的资源隔离与安全保障. docker组成: docker client.docker server.docker组件(镜像(image).容器(contain ...

  3. spring 整合hibernate注解时候,出现“Unknown entity: com.ssh.entry.Admin; nested exception is org.hibernate.MappingException: Unknown entity: com.ssh.entry.Admin”异常的问题

    今天学习使用ssh框架的时候,出现一个异常,弄了好久才找到,在这记录一下,我的sb错误1.spring整合hibernate,取代*.hbm.xml配置文件   在applicationContext ...

  4. 软件工程第二周PSP

  5. php中array_map和array_walk的使用对比

    一.array_map() 1.array_map() 函数将用户自定义函数作用到数组中的每个值上,并返回用户自定义函数作用后的带有新值的数组,若函数作用后无返回值,则对应的新值数组中为空. 2.回调 ...

  6. TCP系列15—重传—5、Linux中RTO的计算

    之前我们介绍的都是协议中给出的RTO计算方法,下面我们看一下linux实现中RTO的计算方法.在linux中维护了srtt.mdev.mdev_max.rttvar.rtt_seq几个状态变量用来计算 ...

  7. jQuery动态添加li标签并添加属性和绑定事件

    代码如下: <%@page import="java.util.ArrayList"%> <%@ page language="java" c ...

  8. 【Docker 命令】- start/stop/restart命令

    docker start:启动一个或多少已经被停止的容器 docker stop:停止一个运行中的容器 docker restart :重启容器 语法: docker start [OPTIONS] ...

  9. IIS部署网部常用问题汇总

    1.unrecognized attribute 'targetframework' A: 需要注册.net framework到iis.步骤如下: (1)'Start' -> 'CMD' (2 ...

  10. codeforces 981 C.Useful Decomposition

    C. Useful Decomposition time limit per test 1 second memory limit per test 256 megabytes input stand ...