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. Android中实现java与PHP服务器(基于新浪云免费云平台)http通信详解

    Android中实现java与PHP服务器(基于新浪云免费云平台)http通信详解 (本文转自: http://blog.csdn.net/yinhaide/article/details/44756 ...

  2. 当"唐僧"没那么容易

    西游记 西游记的故事,无人不知. 但西游记里面的哲学与道理,却仍然值得我们去思考. 记得之前曾有一篇文章写到了西游记与团队管理,师徒四人就是一个完美的团队.之所以能够爬山涉水.克服万难,求得真经,无疑 ...

  3. javascript 与和非

    || :  在javascript中,返回第一个真值,除非都是假值返回最后一个值(也是假值). 1 || 0; 0 || 1; 0 || 0; 0 || undefined; // undefined ...

  4. jsoncpp用法通俗易懂之解析

    刚工作不久,最近遇到一个要解析一个web服务器发过来的json格式的文件,文件如下: { "global": { "renew": "true&quo ...

  5. windows证书地址

    C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys 用certutil -sto ...

  6. 51nod 1348 乘积之和

    用(r-l+2)维向量f[l,r]表示区间[l,r]内选i个数(0<=i<=r-l+1)相乘的所有方案之和,可以发现f[l,r]=f[l,m]*f[m+1,r],题目模数100003较小, ...

  7. Dell vsotro 14 3000系列从win10重装win7

    1. F2启动进入新的BIOS界面,首先Disable Secure Boot,然后把UEFI改为Legeacy模式,当然是改不回来的,不知道为什么: 2. 插入U盘(老毛桃+UEFI启动镜像): 3 ...

  8. 使用eclipse和maven生成java web程序war包

    一.eclipse中,在需要打包的项目名上右击,然后把鼠标光标指向弹出框中的“run as”: 二.之后会看到在这个弹出框的右侧会出现一个悬浮窗,如下: 三.在上边的第二个悬浮窗鼠标点击“maven  ...

  9. 黄聪:WordPress动作钩子函数add_action()、do_action()源码解析

    WordPress常用两种钩子,过滤钩子和动作钩子.过滤钩子相关函数及源码分析在上篇文章中完成,本篇主要分析动作钩子源码. 然而,在了解了动作钩子的源码后你会发现,动作钩子核心代码竟然跟过滤钩子差不多 ...

  10. protobuffer序列化

    一. 描述对象的proto文件 第一行package:对象经过protobuffer编译后形成java文件,这个文件放在按照package新建的文件夹内 java_package:java类的包名 j ...