题目:

  You've been invited to a party. The host wants to divide the guests into 2 teams for party games, with exactly the same number of guests on each team. She wants to be able to tell which guest is on which team as she greets them when they arrive. She'd like to do so as easily as possible, without having to take the time to look up each guest's name on a list.

  Being a good computer scientist, you have an idea: give her a single string, and all she has to do is compare the guest's name alphabetically to that string. To make this even easier, you would like the string to be as short as possible.

Given the unique names of n party guests (n is even), find the shortest possible string S such that exactly half the names are less than or equal to S, and exactly half are greater than S. If there are multiple strings of the same shortest possible length, choose the alphabetically smallest string from among them.

Input

There may be multiple test cases in the input.

Each test case will begin with an even integer n (2n1, 000) on its own line.

On the next n lines will be names, one per line. Each name will be a single word consisting only of capital letters and will be no longer than 30 letters.

The input will end with a `0' on its own line.

Output

For each case, print a single line containing the shortest possible string (with ties broken in favor of the alphabetically smallest) that your host could use to separate her guests. The strings should be printed in all capital letters.

Sample Input

4
FRED
SAM
JOE
MARGARET
2
FRED
FREDDIE
2
JOSEPHINE
JERRY
2
LARHONDA
LARSEN
0

Sample Output

K
FRED
JF
LARI   题意是给你一些字符串,按照字典序排好以后用一个字符串c将它们平均分开为两半,这个c要大于等于一边的所有字符串,小于另一边的所有字符串,同时要求c是最短的。
  排位赛没有做出来,后来看到盛爷的代码以后发现原来可以暴力枚举过。
  做法是先对这些字符串排序,去中间的两个串,然后按照长度从短到长枚举c,对于每一个位置都从a到前面那个字符串的当前位的字母,然后判断当前的c是否大于等于前面的串小于后面的串,如果是,就输出,否则继续枚举下一位。 代码:
 #include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#define MAX 1000
using namespace std; string s[MAX];
string c; void check(int n)
{
int j;
c="";
j=;
while()
{
c+='A';
while(c[j]<='Z')
if(s[n]>c) c[j]++;
else break;
if(c[j]<='Z' && s[n]<=c && c<s[n+]) return ;
if(s[n][j]!=c[j]) c[j]--;
j++;
}
} int main()
{
int n,i;
while(cin>>n,n)
{
c.clear();
for(i=;i<n;i++)
{
s[i].clear();
cin>>s[i];
}
sort(s,s+n);
n=n/-;
check(n);
cout<<c<<endl;
}
return ;
}

6196

												

UVALive Archive - 6196 - Party Games的更多相关文章

  1. 【暑假】[实用数据结构]UVAlive 4329 Ping pong

    UVAlive 4329 Ping pong 题目: Ping pong Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: % ...

  2. Networked Graphics: Building Networked Games and Virtual Environments (Anthony Steed / Manuel Fradinho Oliveira 著)

    PART I GROUNDWORK CHAPTER 1 Introduction CHAPTER 2 One on One (101) CHAPTER 3 Overview of the Intern ...

  3. Asphyre Sphinx is a cross-platform framework for developing 2D/3D video games and interactive business applications

    Introduction Introduction Asphyre Sphinx is a cross-platform framework for developing 2D/3D video ga ...

  4. 记一个mvn奇怪错误: Archive for required library: 'D:/mvn/repos/junit/junit/3.8.1/junit-3.8.1.jar' in project 'xxx' cannot be read or is not a valid ZIP file

    我的maven 项目有一个红色感叹号, 而且Problems 存在 errors : Description Resource Path Location Type Archive for requi ...

  5. Unity性能优化(3)-官方教程Optimizing garbage collection in Unity games翻译

    本文是Unity官方教程,性能优化系列的第三篇<Optimizing garbage collection in Unity games>的翻译. 相关文章: Unity性能优化(1)-官 ...

  6. Unity性能优化(4)-官方教程Optimizing graphics rendering in Unity games翻译

    本文是Unity官方教程,性能优化系列的第四篇<Optimizing graphics rendering in Unity games>的翻译. 相关文章: Unity性能优化(1)-官 ...

  7. Flashback Data Archive ( Oracle Total Recall ) introduced in 11g

    Flashback Data Archive feature is part of Oracle Total Recall technology. Flashback Data Archive fea ...

  8. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  9. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

随机推荐

  1. Openstack能解决这些问题吗?请各位大侠一起来讨论

    1.10万规模的虚拟机,每一个虚拟机能够在不论什么一个计算节点上启动,该怎样做?计算,存储,网络都是怎么拉通与配合的? 2.用户怎样自己定义业务网络,怎样解决网络不够用的情况?正常就4096个vlan ...

  2. Android EditText技巧总结

    一.默认不获取焦点: 在布局文件的父控件中,设置如下属性: android:focusable="true" android:focusableInTouchMode=" ...

  3. case when in sql server's stored procedure

    https://docs.microsoft.com/en-us/sql/t-sql/language-elements/case-transact-sql Evaluates a list of c ...

  4. Android WiFi开发教程(三)——WiFi热点数据传输

    在上一篇文章中介绍了WiFi的搜索和连接,如果你还没阅读过,建议先阅读上一篇Android WiFi开发教程(二)——WiFi的搜索和连接.本篇接着简单介绍手机上如何通过WiFi热点进行数据传输. 跟 ...

  5. Java之POI读取Excel的Package should contain a content type part [M1.13]] with root cause异常问题解决

    Java之POI读取Excel的Package should contain a content type part [M1.13]] with root cause异常问题解决 引言: 在Java中 ...

  6. SPOJ GSS 系列

    来怒做GSS系列了: GSS1:https://www.luogu.org/problemnew/show/SP1043 这题就是维护一个 sum , mx , lmx , rmx,转移时用结构体就好 ...

  7. html5 窗口之间的通信

    一般窗口通信分为三种: iframe嵌套:多个iframe之间通信. 父页面操作子页面元素:oFrame.contentWindow.document.body. 父页面调用子页面方法:oFrame. ...

  8. CSS3 中弹性盒模型--容器的属性

    1.display : flex | inline-flex注意,设为 Flex 布局以后,子元素的float.clear和vertical-align属性 将失效. 2.flex-direction ...

  9. BZOJ 4810 莫队+bitset

    思路: 看完这道题根本没有思路啊.... 然后我就膜拜了一波题解... 这神tm乱搞思路 维护两个bitset 第一个bitset代表当前区间哪些数出现过 第二个bitset是 maxp-p出现过 差 ...

  10. 2013 ACM/ICPC Asia Regional Changsha Online - J

    原题戳这里. 题意: 有一未知列数a1,a2,a3.....an, 已知s[i]=a[i-1]+a[i]+a[i]  (1<i<n) s[1]=a[1]+a[2]; s[n]=a[n-1] ...