题目:

  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. 二维矩阵相乘 in C++

    #include <iostream> #include <vector> #include <string> #include <sstream> # ...

  2. php 制作略缩图

    一.需求 最近公司的项目中有个需求,就是用户上传自己的微信二维码,然后系统会自动将用户的微信二维码合并到产品中 二.分析 因为该系统是手机端的,所以从用户端的体验出发,用户当然是直接在微信上保存二维码 ...

  3. java多线程编程之synchronized

    synchronized是用来解决多线程情况下的线程安全问题的,它可以修饰方法也可以修饰语句块 , 那么什么情况下是线程安全和线程不安全呢 ? 方法内的变量是线程安全的 , 类的实例变量是非线程安全的 ...

  4. UIView动画基础

    1 Position 平移 [UIView animateWithDuration:1.0 animations:^{ _blueView.centerX = self.view.width -100 ...

  5. 笔记《javascript高级程序设计》 第12章 DOM2和DOM3

    DOM2 级核心:在 1 级基础上构建,为节点添加更多方法和属性 DOM2 级视图:为文档定义了基于样式信息的不同视图 DOM2 级事件:说明了如何使用事件和DOM文档交互 DOM2 级样式:如何以编 ...

  6. 计算某个时间段(2017-10-01 2017-12-01)内svn更新文件的MD5

    #!/bin/sh svn up svn log -v -r {$1}:{$2} | grep / | grep -v xxx | sort -f -u | uniq | awk -F 'xxxx' ...

  7. 后端springmvc,前端html5的FormData实现文件断点上传

    前言 最近项目中有使用到文件断点上传,得空便总结总结,顺便记录一下,毕竟“好记性不如烂笔头”. 后端代码: package com.test.controller; import java.io.Bu ...

  8. VMWare虚拟机移动

    1.  背景: 虚拟机:VM3 原安装路径:C:\Users\Administrator\Documents\Virtual Machines 移动到目标路径:D:\Virtual Machines ...

  9. 搭建Hadoop所遇过的坑

    问题1: 报错信息如下: Container exited with a non-zero exit code 143 Killed by external signal 解决方案: 分配的资源不够, ...

  10. dubbo之回声测试

    回声测试 回声测试用于检测服务是否可用,回声测试按照正常请求流程执行,能够测试整个调用是否通畅,可用于监控. 所有服务自动实现 EchoService 接口,只需将任意服务引用强制转型为 EchoSe ...