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 as they arrive, and 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 determine whether the guest's name is alphabetically less than or greater than
that string.
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’s more than one string of the shortest length, output the one that comes
first alphabetically.
Input
There will be multiple test cases in the input. Each test case will begin with an even
integer n (2≤n≤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 at least one
letter and no longer than 30 letters. All of the names in a test case will be unique. The
input will end with a 0 on its own line.
Output
For each case, output the alphabetically first of all of the shortest possible strings that
your host could use to separate her guests. Output this string using all upper case
letters. Do not output any spaces. Do not put a blank line between outputs.

Sample Input
4
FRED
SAM
JOE
MARGARET
2
FRED
FREDDIE
2
JOSEPHINE
JERRY
0

Sample Input
4
FRED
SAM
JOE
MARGARET
2
FRED
FREDDIE
2
JOSEPHINE
JERRY
0

2012  Southeast USA Regional Programming Contest

http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11397

题意:

串A,串B ,寻找串C ,s.t.   A<=C<B 且满足C.length最小 。

也就是2个指针的应用,值得一做的试题。

#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std ;
typedef long long LL ;
const int N_size= ;
struct Stu{
char name[N_size] ;
friend bool operator < (Stu A ,Stu B){
return strcmp(A.name,B.name)< ;
}
};
Stu stu[] ;
int N ;
string gao(){
string A ,B ;
string ans ;
char ans_char[N_size] ;
A=string(stu[N/].name) ;
B=string(stu[N/+].name) ;
int i= ;
int j= ;
while(i<A.length()&&j<B.length()){
if(A[i]==B[j]){
ans_char[i]=A[i] ;
i++ ;
j++ ;
}
else{
ans_char[i]=A[i] ;
ans_char[i+]='\0' ;
ans=string(ans_char) ;
if(A<=ans&&ans<B)
return ans ; if(A[i]<'Z'){
ans_char[i]=A[i]+ ;
ans_char[i+]='\0' ;
ans=string(ans_char) ;
if(A<=ans&&ans<B)
return ans ;
}
ans_char[i]=A[i] ;
i++ ;
j++ ;
}
}
if(i==A.length())
return A ;
for(j=i;j<A.length();j++){
ans_char[j]=A[j] ;
ans_char[j+]='\0' ;
ans=string(ans_char) ;
if(A<=ans&&ans<B)
return ans ;
if(A[j]<'Z'){
ans_char[j]=A[j]+ ;
ans_char[j+]='\0' ;
ans=string(ans_char) ;
if(A<=ans&&ans<B)
return ans ;
}
ans_char[j]=A[j] ;
}
}
int main(){
while(scanf("%d",&N)&&N){
for(int i=;i<=N;i++)
scanf("%s",stu[i].name) ;
sort(stu+,stu++N) ;
cout<<gao()<<endl ;
}
return ;
}

Party Games的更多相关文章

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

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

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

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

  3. Learning in Two-Player Matrix Games

    3.2 Nash Equilibria in Two-Player Matrix Games For a two-player matrix game, we can set up a matrix ...

  4. (转) Playing FPS games with deep reinforcement learning

    Playing FPS games with deep reinforcement learning 博文转自:https://blog.acolyer.org/2016/11/23/playing- ...

  5. Favorite Games

    Samurai II: Vengeance: http://www.madfingergames.com/games

  6. CF456D A Lot of Games (字典树+DP)

    D - A Lot of Games CF#260 Div2 D题 CF#260 Div1 B题 Codeforces Round #260 CF455B D. A Lot of Games time ...

  7. GDC2016 Epic Games【Bullet Train】 新风格的VR-FPS的制作方法

    追求“舒适”和“快感”的VR游戏设计方法   http://game.watch.impress.co.jp/docs/news/20160318_749016.html     [Bullet Tr ...

  8. Supercell only provide the best games for players

    Supercell only provide the best games for players Supercell start to change all, Supercell's first t ...

  9. 读书笔记2014第6本:《The Hunger Games》

    以前从未读过一本完整的英文小说,所有就在今年的读书目标中增加了一本英文小说,但在头四个月内一直没有下定决定读哪一本.一次偶然从SUN的QQ空间中看到Mockingjay,说是不错的英文小说,好像已经是 ...

  10. [codeforces 325]B. Stadium and Games

    [codeforces 325]B. Stadium and Games 试题描述 Daniel is organizing a football tournament. He has come up ...

随机推荐

  1. WCF学习心得------(六)数据协定

    --前言 最近各种事忙的把之前的WCF学习给耽误了一些,今天抽时间把之前的学习内容给总结了一下,因为知识点比较细碎没有做太多的练习示例,只是对其中关键的知识点做了总结,希望可以对大家有所帮助. 第六章 ...

  2. 解决SQLite3数据库Error: database disk image is malformed

    这种错误的提示一般都是数据库文件出现了问题,具体导致问题的原因不必深究,我们只讨论这种问题的饿解决方法: 比如数据库:test.db 这里还要分两种情况: 情况一: sqlite3 test.db & ...

  3. MySQL存储引擎【InnoDB、MyISAM、Memory】

    数据库,MySQL这样存在多存储引擎的数据库软件,清楚常见的存储引擎的区别,使用合适的存储引擎,使得项目跑的更顺畅,有时候对于一个项目,甚至比项目本身都重要.这篇文章,旨在浅谈常见的三种存储引擎的区别 ...

  4. Python列表,元组,字典,序列,引用

    1.列表 # Filename: using_list.py # This is my shopping list shoplist=["apple", "mango&q ...

  5. DHCP协议讲解

    一.DHCP服务介绍: DHCP为动态主机配置协议,该协议能自动配置主机的IP地址.子网掩码.网关及DNS服务器等TCP/IP信息.DHCP可以降低客户机IP地址配置的复杂度和网络管理成本. DHCP ...

  6. Sublime text2用户自定义配置

    [{ "keys": ["ctrl+d"], "command": "run_macro_file", "ar ...

  7. Oracle-decode函数

    decode函数 简单例子:管理员登录Oracle select sid, username, decode(command, 0, 'None', 2, 'Insert', 3, 'Select', ...

  8. [Android NDK/JNI-1A]-开发环境搭建

    NDK简介 NDK能干什么:NDK使得在android中,java可以调用C 函数库. 1.Android平台从诞生起,就已经支持C.C++开发.众所周知,Android的SDK基于Java实现,这意 ...

  9. CF 274B Zero Tree 树形DP

    A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following cond ...

  10. HTML5与HTML4的区别

    一.推出的理由及目标 web浏览器之间的兼容性很低 文档结构不够明确 web应用程序的功能受到了限制 二.语法的改变 内容类型 文件扩展名html htm  内容类型 texthtml   二者不变 ...