Party Games UVA
来源:互联网 发布:c语言的科学和艺术 pdf 编辑:程序博客网 时间:2024/05/21 09:31
题目传送门
题意:输入一个n(n是偶数)个字符串的集合,找一个长度最短的字符串S,使得集合当中恰好有一半的字符串小于等于S,有一半大于等于S,如果有多解的话,输出字典序最小的解。
思路:求出来中间的两个字符串然后贪心即可。
#include <algorithm>#include <cmath>#include <cstdio>#include <cstring>#include <fstream>#include <iostream>#include <list>#include <map>#include <queue>#include <set>#include <sstream>#include <stack>#include <string>#include <time.h>#include <vector>#define MAXN 200000#define MAXE 210#define INF 10000000#define MOD 1000000007#define LL long long#define pi acos(-1.0)using namespace std;int main() { std::ios::sync_with_stdio(false); int n; while (cin >> n && n) { vector<string> vec; string str; for (int i = 0; i < n; ++i) { cin >> str; vec.push_back(str); } sort(vec.begin(), vec.end()); string temp1 = vec[n / 2 - 1]; string temp2 = vec[n / 2]; bool flag = false; for (int i = 0; i < temp1.length(); ++i) { string temp = temp1.substr(0, i); string s = temp1.substr(0, i + 1); if (s >= temp1 && s <= temp2) { flag = true; cout << s << endl; break; } else { if (temp1[i] == 'Z') { continue; } else { temp += (char)(temp1[i] + 1); if (temp >= temp1 && temp < temp2) { cout << temp << endl; flag = true; break; } } } } if (!flag) { cout << temp1 << endl; } }}/*4FREDSAMJOEMARGARET2FREDFREDDIE2JOSEPHINEJERRY2LARHONDALARSEN0*/
阅读全文
0 0
- Uva - 1610 - Party Games
- uva 1610Party Games
- UVA 1610 - Party Games
- UVA 1610 Party Games
- uva 1610 Party Games
- UVA 1610 Party Games
- Party Games UVA
- Party Games UVA
- UVA 1610 Party Games
- Party Games UVA
- Party Games UVA
- UVA - 1610 Party Games 贪心
- UVA 1610(p253)----Party Games
- UVa 1610 - Party Games(细节处理)
- UVa #1610 Party Games (习题8-2)
- UVa:1610 Party Games(字符串处理)
- uva 1610——Party Games
- UVA 1610 Party Games 模拟 有细节
- 程序员,如何从平庸走向理想?
- SmartRefreshLayout集成笔记,实现下拉刷新上拉加载更多。
- 仿微软写了一个win32 计算器小程序
- SQL整理
- [RK3288][Android6.0] 调试笔记 --- 查看Activity对应调用的进程
- Party Games UVA
- RelativeLayout的一个特性
- slidingmenu侧拉页面
- CAN 、I2S、I2C、SPI 、SSP总线简介
- Integer 类型的变量,编译器不会给你默认值,不赋值会报错
- 代码详解のTreeMap实现原理
- 定时器
- uploadfile
- C#中ArrayList类的使用方法