UVA - 1610 - Party Games(模拟or枚举)
来源:互联网 发布:整套python教学视频 编辑:程序博客网 时间:2024/06/06 18:35
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 (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 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
题意:给出偶数个名字,保证每个名字都不同,求一个字符串使得可以通过比较将名字分成两个team。
最开始用模拟做,排序后比较中间两个字符串,比的快哭了QAQ 结果还脑子糊想不清楚,难过。
队长大大做完后说你个渣渣,直接暴力搜啊23333
暴力枚举每个位置的字符,枚举一次比一次,一旦满足条件(大于等于n/2+1位置的,小于n/2位置的),直接输出。队长你厉害orzzzzzzzzzzz
#include <stdio.h>#include <math.h>#include <string.h>#include <algorithm>#include <queue>#include <iostream>#include <assert.h>#define INF 0x3f3f3f3fusing namespace std;int main(){ int n; string s[1005]; while (cin >> n) { if(n == 0) break; for (int i = 0; i < n; i++) { cin >> s[i]; } sort(s, s + n); //最开始用char做不会排序2333 发现string真方便 int m1 = n / 2 - 1; string ans = ""; bool flag = 0; int cnt = 0; while (1) { string s2 = ""; for (char i = 'A'; i <= 'Z'; i++) { s2 = ans + i; if (s2 >= s[m1] && s2 < s[m1 + 1]) { cout << s2 << endl; flag = 1; break; } } if (flag) break; ans += s[m1][cnt++]; } } return 0;}
- UVA - 1610 - Party Games(模拟or枚举)
- UVA 1610 Party Games 模拟 有细节
- Uva - 1610 - Party Games
- uva 1610Party Games
- UVA 1610 - Party Games
- UVA 1610 Party Games
- uva 1610 Party Games
- UVA 1610 Party Games
- UVA 1610 Party Games
- UVa 1610 - Party Games(细节处理)
- UVa:1610 Party Games(字符串处理)
- [UVa 1610] 聚会游戏(Party Games)
- UVA - 1610 Party Games 贪心
- UVA 1610(p253)----Party Games
- UVa #1610 Party Games (习题8-2)
- uva 1610——Party Games
- UVA 1610-Party Games(聚会游戏)
- uva 1610 Party Games (贪心+STL字符串)
- Android commond 进入系统目录
- SpringMVC rest风格(Post增 Delete删 Put改 get查)
- 【并发】ThreadLocal源码浅析
- 安卓三班JAVA阶段型考试
- 书单,资源,待学习
- UVA - 1610 - Party Games(模拟or枚举)
- [HDU2463] USTC campus network [2008 Asia Hefei Regional Contest Online H]
- SQL执行顺序
- mac android studio快捷键之-查看一个接口有哪些实现
- 【poj3045】牛的杂技
- iOS 怎麼搭建項目框架
- div 透明
- 【数据结构】单链表—冒泡排序
- LoadRunner学习移动App的脚本录制