博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Party Games
阅读量:6324 次
发布时间:2019-06-22

本文共 2455 字,大约阅读时间需要 8 分钟。

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

 

 题意:

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

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

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#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=32 ;struct Stu{ char name[N_size] ; friend bool operator < (Stu A ,Stu B){ return strcmp(A.name,B.name)<0 ; }};Stu stu[1008] ;int N ;string gao(){ string A ,B ; string ans ; char ans_char[N_size] ; A=string(stu[N/2].name) ; B=string(stu[N/2+1].name) ; int i=0 ; int j=0 ; while(i

 

转载于:https://www.cnblogs.com/liyangtianmen/p/3357746.html

你可能感兴趣的文章
深度|余凯:基于深度学习的自动驾驶之路
查看>>
ORA-00845: MEMORY_TARGET not supported on this system
查看>>
数据库存储结构
查看>>
国内银行CNAPS CODE 查询 苹果开发者,应用内购,需要填写税务相关信息必须的...
查看>>
Linux下抓图工具shutter
查看>>
javascript获取select,checkbox,radio的值
查看>>
Metro Win8风格的按钮(Filp翻转)
查看>>
cookies/session/token
查看>>
清除代码异味
查看>>
【转】从知乎上看到“全栈开发者”讨论之后的自黑
查看>>
Java-IO流
查看>>
Linux入门-6 Linux网络基本配置
查看>>
洗礼灵魂,修炼python(22)--自定义函数(3)—函数作用域,闭包
查看>>
newcoder Tachibana Kanade Loves Probability(小数点后第k位)题解
查看>>
vue项目未加载完成前显示loading...
查看>>
windows 与linux 下用C++读取sqlite实现文件复制(一)
查看>>
IOS 5 中为什么outlet 输出口总是设定成弱类型(weak)呢
查看>>
Read-Copy Update (RCU)
查看>>
基于centos系统,系统基本检查及巩固
查看>>
在以太坊上如何取消/修改已经提交的交易
查看>>