http://codeforces.com/contest/794/problem/C

题意:

有两个人要为公司起名字,每个人手中都有n个字符,现在要取一个n个字符长度的公司名。两人轮流取名,每次选择一个字符,可以任意选择放在1~n还未放置字符的位置上,每个字符限用一次。

现在第一个人希望公司名字典序越小越好,而第二个人希望字典序越大越好。输出最后的公司名。

思路:

首先肯定是要排序的,第一个人肯定去用前面最小的几个,而第二个人肯定去用前面最大的几个。

轮到第一个人时,我们首先将他手中最小的字符和第二个人手中最大的字符相比,如果此时最小字符大于等于了第二个人的最大字符,那么此时就把最大的字符放置最末尾。否则的话就把最小的放到首位。

轮到第二个人时同理分析。

 #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
typedef long long LL; const int maxn=*1e5+; char s1[maxn],s2[maxn];
char ans[maxn]; bool cmp1(char a,char b)
{
return a<b;
} bool cmp2(char a,char b)
{
return a>b;
} int main()
{
//freopen("D:\\input.txt","r",stdin);
while(cin>>s1>>s2)
{
int len=strlen(s1);
sort(s1,s1+len,cmp1);
sort(s2,s2+len,cmp2);
int p_left=;
int p_right=len/+(len&)-;
int q_left=;
int q_right=len/-;
int l=,r=len-;
int flag=;
for(int i=;i<len;i++)
{
if(flag)
{
if(s1[p_left]>=s2[q_left]) ans[r--]=s1[p_right--];
else ans[l++]=s1[p_left++];
flag=;
}
else
{
if(s2[q_left]<=s1[p_left]) ans[r--]=s2[q_right--];
else ans[l++]=s2[q_left++];
flag=;
}
}
for(int i=;i<len;i++)
printf("%c",ans[i]);
}
return ;
}

Codeforces Round #414 C. Naming Company的更多相关文章

  1. 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 ...

  2. Tinkoff Challenge - Final Round (Codeforces Round #414, rated, Div. 1 + Div. 2) 继续跪一把

    这次的前三题挺简单的,可是我做的不快也不对. A. Bank Robbery time limit per test 2 seconds memory limit per test 256 megab ...

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

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

  4. Tinkoff Challenge - Final Round (Codeforces Round #414, rated, Div. 1 + Div. 2)

    A: 思路:就是找b,c之前有多个s[i] 代码: #include<stdio.h>#define ll long longusing namespace std;ll a,b,c;in ...

  5. Codeforces Round #414 A. Bank Robbery

    A. Bank Robbery time limit per test 2 seconds memory limit per test   256 megabytes   A robber has a ...

  6. 【构造】Tinkoff Challenge - Final Round (Codeforces Round #414, rated, Div. 1 + Div. 2) D. Labelling Cities

    考试的时候想的是,将所有的完全子图缩起来,然后如果剩下的是一条链,依次对其进行标号即可. 看了官方题解,发现完全子图这个条件太强了,缩点的条件仅仅需要保证原本两个点的“邻接表”相同即可.(注意这里的“ ...

  7. Codeforces Round #414

    A =w= B qvq C(贪心) 题意: Alice和Bob分别有长度为n(n<=1e5)的字符串,Alice先手,每次从自己的字符串中抽出一个字母放到新字符串的某个位置,一共轮流n次,也就是 ...

  8. codeforces round #414 div1+div2

    A:判断一下就可以了 #include<bits/stdc++.h> using namespace std; typedef long long ll; int a, b, c, n; ...

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

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

随机推荐

  1. D. Two Paths---cf14D(树的直径)

    题目链接:http://codeforces.com/problemset/problem/14/D 题意:有n个city ; n-1条路:求断开一条路之后分成的两部分所构成的树的直径的积最大是多少: ...

  2. 16.Update Methods-官方文档摘录

    这里没什么好说的,直接贴文了 MongoDB provides the following methods for updating documents in a collection: db.col ...

  3. MySQL优化(三):优化数据库对象

    二.优化数据库对象 1.优化表的数据类型 应用设计的时候需要考虑字段的长度留有一定的冗余,但不推荐很多字段都留有大量的冗余,这样既浪费磁盘空间,也在应用操作时浪费物理内存. 在MySQL中,可以使用函 ...

  4. JavaWeb-HttpServletResponse对象一

    web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象,和代表响应的response对象.resquest和response对象既然代表请求和响应,那么要 ...

  5. 详解C++中命名空间的意义和用法

    看过鸡啄米的C++编程入门系列教程的朋友,应该能注意到,在其中的很多实例中,都有这么一条语句:using namespace std;,即使用命名空间std,其作用就是规定该文件中使用的标准库函数都是 ...

  6. Docker中安装配置Oracle数据库

    本文使用的OS是Ubuntu([16.04.1_server][1])[注:Ubuntu是安装在vmware虚拟机上的]. 其他的Oracle连接工具:[sqldeveloper-4.1.5.21.7 ...

  7. 007-Hadoop Hive sql语法详解2-修改表结构

    一.表 更改表名:ALTER TABLE table_name RENAME TO new_table_name 增加表的元数据信息:ALTER TABLE table_name SET TBLPRO ...

  8. linux内核源代码、配置与编译

    内核源代码下载:www.kernel.org Linux内核源代码采用树形结构进行组织,非常合理地把功能相关的文件都放在同一个子目录下,使得程序更具可读性. linux内核代码最好不要在windows ...

  9. HTML5游戏开发系列教程8(译)

    原文地址:http://www.script-tutorials.com/html5-game-development-lesson-8/ 这是我们最新一篇HTML5游戏开发系列文章.我们将继续使用c ...

  10. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem A. Arithmetic Derivative

    题目:Problem A. Arithmetic DerivativeInput file: standard inputOutput file: standard inputTime limit: ...