UVA 1610 Party Game(逼近)
来源:互联网 发布:sql中is not null 编辑:程序博客网 时间:2024/05/29 17:48
题意
给出个数为偶数的字符串数组,寻找一个字典序尽量小的字符串将该数组分割成,前一半小于等于该字符串,并后一半大于其。
分析
只需找到排序后最靠中间的两个字符串,在中间插入即可。
刚开始的想法,是分情况讨论,可是情况有点多,自己讨论了半天都没有A掉。
于是想直接构造一个字符串,通过层层逼近,来获得一个答案。
逼近 — 匹配— 修正。
大胆的探索,错了就改,有点二分的意思。。。
#include <bits/stdc++.h>using namespace std;//层层逼近string judge(string a, string b){ int n = a.size(); int id = 0; string ans = ""; ans += 'A'; while(id < n) { while(ans[id] <= 'Z' && ans < a) ++ans[id];//逼近 if(ans[id] <='Z' && ans >= a && ans < b) return ans;//匹配 if(ans[id] != a[id]) --ans[id];//修正 ans += 'A'; id++; }}string s[1100];int main(){ //freopen("in.txt","r",stdin); int n; string a, b; while(cin >> n && n) { for(int i = 0; i < n; i++) cin >> s[i]; sort(s, s+n); a = s[n/2-1]; b = s[n/2]; string ans = judge(a,b); cout << ans << endl; } return 0;}
0 0
- UVA 1610 Party Game(逼近)
- UVa 1610 - Party Games(细节处理)
- UVa:1610 Party Games(字符串处理)
- [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(p253)----Party Games
- UVA - 1610 - Party Games(模拟or枚举)
- UVa #1610 Party Games (习题8-2)
- uva 1610——Party Games
- UVA 1610 Party Games 模拟 有细节
- UVA 1610-Party Games(聚会游戏)
- convert RGB image with hole into binary image with hole filled
- {模板}矩阵快速幂
- linux文件操作之open函数说明
- 分类和回归树,随机森林,霍夫森林(CART,random forests,hough forests)
- 六款值得推荐的android(安卓)开源框架简介
- UVA 1610 Party Game(逼近)
- poj 3320 A - Jessica's Reading Problem
- Java的7个动作指令
- 猜数字(二)
- git搭建博客(一)
- 解决Mac Sublime text 2不能显示中文问题
- Atitit.人力资源管理原理与概论
- 屏蔽、禁止鼠标双击选中文字
- bzoj2186 莎拉公主的困惑【线性筛+欧拉函数+逆元】