博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA - 1610 Party Games(聚会游戏)(构造)
阅读量:4705 次
发布时间:2019-06-10

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

题意:输入一个n(2<=n<=1000,n是偶数)个字符串的集合D,找一个长度最短的字符串S(不一定在D中出现),使得D中恰好一半串小于等于S,另一半串大于S。如果有多解,输出字典序最小的解。

分析:找到最中间的两个串,直接按位构造。

#pragma comment(linker, "/STACK:102400000, 102400000")#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define Min(a, b) ((a < b) ? a : b)#define Max(a, b) ((a < b) ? b : a)typedef long long LL;typedef unsigned long long ULL;const int INT_INF = 0x3f3f3f3f;const int INT_M_INF = 0x7f7f7f7f;const LL LL_INF = 0x3f3f3f3f3f3f3f3f;const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};const int MOD = 1e9 + 7;const double pi = acos(-1.0);const double eps = 1e-8;const int MAXN = 1e3 + 10;const int MAXT = 10000 + 10;using namespace std;string s[MAXN];string solve(int n){ int mid = n / 2; int len = s[mid - 1].size(); string ans = ""; ans += 'A'; int i = 0; while(i < len){ while(ans[i] < 'Z' && ans < s[mid - 1]) ++ans[i];//只要i不是len-1且s[mid - 1][i]不是Z,得到的ans[i]都会比s[mid - 1]恰好大1,而如果i等于len-1,则得到的ans与s[mid-1]正好相等 if(ans >= s[mid - 1] && ans < s[mid]) return ans; if(s[mid - 1][i] != ans[i]) --ans[i];//如果s[mid - 1][i]不是Z,需要减1 ans += 'A'; ++i; }}int main(){ int n; while(scanf("%d", &n) == 1){ if(!n) return 0; for(int i = 0; i < n; ++i) cin >> s[i]; sort(s, s + n); printf("%s\n", solve(n).c_str()); } return 0;}

  

转载于:https://www.cnblogs.com/tyty-Somnuspoppy/p/6374806.html

你可能感兴趣的文章
Vue疑难杂症
查看>>
常用的JQuery数字类型验证正则表达式
查看>>
golang在Windows下Sublime Text开发调试环境的配置
查看>>
spring boot 错误处理之深度历险
查看>>
PHP扩展开发WINDOWS配置
查看>>
Screen2EXE录屏|录制视频
查看>>
二十. StringFromFile与counter函数
查看>>
sqlserver 数据库 的数据库个数统计 表个数统计 表的数据量统计(转载)
查看>>
C++生成随机数
查看>>
raphael 支持group(简)
查看>>
poj 3050 Hopscotch(暴力+dfs)
查看>>
USACO SEC.1.3 No.2 Barn Repair
查看>>
Nginx编译安装、启动、配置详解——1.8.1版本
查看>>
this.$router 和this.$route 的区别
查看>>
Linux--Centos7开机启动 mysql5.7.19
查看>>
2018-2019-1 20165220 《信息安全系统设计基础》第6周学习总结
查看>>
Java 获取汉字串首字母并大写和获取汉字的全拼,英文字符不变
查看>>
《构建之法》前三章的读后感
查看>>
12306
查看>>
mac 开发人员的简单配置
查看>>