Naming Company CodeForces - 794C
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
tinkoff
zscoder
fzfsirk
xxxxxx
xxxxxx
xxxxxx
ioi
imo
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的更多相关文章
- Naming Company CodeForces - 794C (博弈,构造)
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little thi ...
- [刷题]Codeforces 794C - Naming Company
http://codeforces.com/contest/794/problem/C Description Oleg the client and Igor the analyst are goo ...
- CodeForces - 794C:Naming Company(博弈&简单贪心)
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little thi ...
- 【codeforces 794C】Naming Company
[题目链接]:http://codeforces.com/contest/794/problem/C [题意] 有n个位置; 两个人; 每个人都有n个字符组成的集合s1,s2(可以有重复元素); 然后 ...
- Codeforces Round #414 C. Naming Company
http://codeforces.com/contest/794/problem/C 题意: 有两个人要为公司起名字,每个人手中都有n个字符,现在要取一个n个字符长度的公司名.两人轮流取名,每次选择 ...
- codeforces 794 C. Naming Company(贪心)
题目链接:http://codeforces.com/contest/794/problem/C 题意:有两个人每个人都有一个长度为n的字符串,两人轮流拿出一个字符串,放在一个长度为n的字符串的指定位 ...
- 【贪心】【multiset】Tinkoff Challenge - Final Round (Codeforces Round #414, rated, Div. 1 + Div. 2) C. Naming Company
考虑两个人,先把各自的集合排个序,丢掉一半,因为比较劣的那一半一定用不到. 然后贪心地放,只有两种决策,要么把一个最优的放在开头,要么把一个最劣的放在结尾. 如果我的最优的比对方所有的都劣(或等于), ...
- 【贪心+博弈】C. Naming Company
http://codeforces.com/contest/794/problem/C 题意:A,B两人各有长度为n的字符串,轮流向空字符串C中放字母,A尽可能让字符串字典序小,B尽可能让字符串字典序 ...
- 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 ...
随机推荐
- [JSON].typeOf( keyPath )
语法:[JSON].typeOf( keyPath ) 返回:[String | Number | Boolean | Json | Array | Function | 空字符] 说明:获取指定键 ...
- nginx 重启报错
错误信息: nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or d ...
- LeetCode 145 ——二叉树的后序遍历
1. 题目 2. 解答 2.1. 递归法 定义一个存放树中数据的向量 data,从根节点开始,如果节点不为空,那么 递归得到其左子树的数据向量 temp,将 temp 合并到 data 中去 递归得到 ...
- 转战Java~
记得16年5月份开始学的Java,当时就是为了学Hadoop才学的Java基础,之后Hadoop没学成,倒是学了Java Web的东西,当时就是玩玩,然后弄了个WeChat后台,就完事了.然后就又回到 ...
- HADOOP docker(五):hadoop用户代理 Proxy user
1.hadoop用户代理简介2.配置3.实验 1.hadoop用户代理简介 hadoop用户代理功能的作用是让超级用户superuser模拟一个普通用户来执行任务.比如用户joe通过oozie提交一个 ...
- Sum of Consecutive Prime Numbers(素数打表+尺取)
Description Some positive integers can be represented by a sum of one or more consecutive prime numb ...
- 团队作业week9 情景测试
一.使用人群:学生.计算机工作者.对计算机感兴趣的人 1.学生:学生是学霸系统的主要用户.学生一般会通过网络寻找与自己的课程,作业有关的信息.首先,可以通过我们的搜索功能在我们的数据库中寻找我们从网络 ...
- 深入了解View的绘制流程
1. ViewRoot ViewRoot是连接WindowManager与DecorView的纽带,View的整个绘制流程的三大步(measure.layout.draw)都是通过ViewRoot完 ...
- Apriori算法详解
一.Apriori 算法概述Apriori 算法是一种最有影响力的挖掘布尔关联规则的频繁项集的 算法,它是由Rakesh Agrawal 和RamakrishnanSkrikant 提出的.它使用一种 ...
- Java入门之:对象和类
Java对象和类 Java作为一种面向对象语言,支持以下基本概念: 多态 继承 封装 抽象 类 对象 实例 方法 重载 本节我们重点研究对象和类的概念: 对象: 对象是类的一个实例,有状态和行为.例如 ...