UVALive Archive - 6196 - Party Games
题目:
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 (2n
1, 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的更多相关文章
- 【暑假】[实用数据结构]UVAlive 4329 Ping pong
UVAlive 4329 Ping pong 题目: Ping pong Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: % ...
- 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 ...
- 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 ...
- 记一个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 ...
- Unity性能优化(3)-官方教程Optimizing garbage collection in Unity games翻译
本文是Unity官方教程,性能优化系列的第三篇<Optimizing garbage collection in Unity games>的翻译. 相关文章: Unity性能优化(1)-官 ...
- Unity性能优化(4)-官方教程Optimizing graphics rendering in Unity games翻译
本文是Unity官方教程,性能优化系列的第四篇<Optimizing graphics rendering in Unity games>的翻译. 相关文章: Unity性能优化(1)-官 ...
- Flashback Data Archive ( Oracle Total Recall ) introduced in 11g
Flashback Data Archive feature is part of Oracle Total Recall technology. Flashback Data Archive fea ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
随机推荐
- codeforces 915D Almost Acyclic Graph 拓扑排序
大意:给出一个有向图,问能否在只去掉一条边的情况下破掉所有的环 解析:最直接的是枚举每个边,将其禁用,然后在图中找环,如果可以就YES,都不行就NO 复杂度O(N*M)看起来不超时 但是实现了以后发现 ...
- [Apple开发者帐户帮助]四、管理密钥(1)创建私钥以访问服务
私钥允许您访问和验证与某些应用服务(如APN,MusicKit和DeviceCheck)的通信.您将在对该服务的请求中使用JSON Web令牌(JWT)中的私钥. 所需角色:帐户持有人或管理员. 在“ ...
- nginx编译安装新模块
nginx的模块是需要重新编译nginx,而不是像apache一样配置文件引用.so 这里以安装第三方ngx_http_google_filter_module模块为例 下载第三方扩展模块ngx_ht ...
- jvm堆外直接内存实现高性能接入层
jvm堆外直接内存实现高性能接入层https://blog.csdn.net/phil_code/article/details/69056086
- 基于bootstarp的Dailog
oaoDailog开发帮助 1. 帮助文档关键字 boostrap模态框oaoDailog 2. 使用场景 当网页上点击某个按钮需要给予用户提示确认,用户点击确认按钮才 ...
- create-react-app 中设置反向代理、项目打包资源引入路径设置及 map 文件
1.配置反向代理 (1)porxy 配置一个代理 修改package.json文件 "proxy":"http://teng.com/website/web", ...
- List 练习
(List)已知有一个Worker 类如下: public class Worker { private int age; private String name; private double sa ...
- Eclipse中配置SVN(步骤简述)
————Eclipse中配置SVN(步骤简述)———— 1.有客户端(tortoiseSVN),服务器端(visualSVN) 两种,根据需要安装,安装后需重启电脑 2.服务器端配置:创建版本库(放工 ...
- SQL Server存储过程作业(二)
阶段1:练习——统计某类型客房的入住客人人数 需求说明 使用存储过程统计在指定类型的客房入住客人的总人数 提示: 存储过程的输入参数是指定的客房类型名称 USE Hotel GO --阶段1:查询入住 ...
- SLAM: 关于Orb_SLAM的使用小综述
0.ORB_SLAM的官方网站:http://webdiis.unizar.es/~raulmur/orbslam/ 1. 参考知乎上对 orb-slam 的评价:orb-slam在众多SLAM方法中 ...