Time Limit: 2000MS | Memory Limit: 65536K | |||
Total Submissions: 7783 | Accepted: 2654 | Special Judge |
Description
John is the only priest in his town. September 1st is the John's busiest day in a year because there is an old legend in the town that the couple who get married on that day will be forever blessed by the God of Love. This year N couples plan to get married on the blessed day. The i-th couple plan to hold their wedding from time Si to time Ti. According to the traditions in the town, there must be a special ceremony on which the couple stand before the priest and accept blessings. The i-th couple need Di minutes to finish this ceremony. Moreover, this ceremony must be either at the beginning or the ending of the wedding (i.e. it must be either from Si to Si + Di, or from Ti - Di to Ti). Could you tell John how to arrange his schedule so that he can present at every special ceremonies of the weddings.
Note that John can not be present at two weddings simultaneously.
Input
The first line contains a integer N ( 1 ≤ N ≤ 1000).
The next N lines contain the Si, Ti and Di. Si and Ti are in the format of hh:mm.
Output
The first line of output contains "YES" or "NO" indicating whether John can be present at every special ceremony. If it is "YES", output another N lines describing the staring time and finishing time of all the ceremonies.
Sample Input
2 08:00 09:00 30 08:15 09:00 20
Sample Output
YES 08:00 08:30 08:40 09:00
题意:
给出 N(1 ~ 1000),代表有 N 个时间。后给出这 N 个时间的起点和终点和消费时间 T 。每个时间点要不从起点开始计算,要不从终点 - T 开始,要求遍历所有的时间并且任意时间之间不能有重叠。若能按要求遍历所有时间,则输出YES和这些时间段,不能则输出NO。
思路:
2 - sat。找到一种确定的关系来建图,于是找到冲突关系,若 si ~ si + T 和 sj ~ sj + T 时间有冲突,且必须选 si 的话,则必须选 ej,即 si -> ej,同时逆否命题 非ej -> 非si 也成立。同理,若 si ~ si + T 和 ej - T ~ ej 有冲突的话,必须选 si 的话,则必须选 sj,即 si -> sj。如此,一共可以判断四次来建图。建图后 2 - sat,强连通后,判断同一个 i 和 n + i 是否在同一个强连通中,不是的话则找拓扑序小的输出即可(因为拓扑序是倒序的)。
判断两个时间段是否重叠的方法(L1,R1,L2,R2):
Min( R1,R2 ) > Max( L1,L2 ) 则两个时间段有重叠(不包括边界),否则则不重叠。
AC:
#include <cstdio> #include <cstring> #include <algorithm> #include <map> #include <stack> #include <queue> using namespace std; const int NMAX = 1005 * 2; const int EMAX = NMAX * NMAX; typedef struct { int sta, End, last; }node; node no[1005]; int n, ind; int v[EMAX], fir[NMAX], Next[EMAX]; int dfs_clock, scc_cnt; int low[NMAX], pre[NMAX], cmp[NMAX]; stack<int> s; void add_edge(int f, int t) { v[ind] = t; Next[ind] = fir[f]; fir[f] = ind; ++ind; } void dfs(int u) { pre[u] = low[u] = ++dfs_clock; s.push(u); for (int e = fir[u]; e != -1; e = Next[e]) { if (!pre[ v[e] ]) { dfs( v[e] ); low[u] = min(low[u], low[ v[e] ]); } else if (!cmp[ v[e] ]) { low[u] = min(low[u], pre[ v[e] ]); } } if (pre[u] == low[u]) { ++scc_cnt; for (;;) { int x = s.top(); s.pop(); cmp[x] = scc_cnt; if (x == u) break; } } } void scc() { scc_cnt = dfs_clock = 0; memset(pre, 0, sizeof(pre)); memset(cmp, 0, sizeof(cmp)); for (int u = 1; u <= 2 * n; ++u) if (!pre[u]) dfs(u); } bool test (int f1, int t1, int f2, int t2) { if (f1 >= t2 || t1 <= f2) return false; return true; } int main() { ind = 0; memset(fir, -1, sizeof(fir)); scanf("%d", &n); for (int i = 1; i <= n; ++i) { char s[10], e[10]; scanf("%s%s%d", s, e, &no[i].last); no[i].sta = ( (s[0] - '0') * 10 + s[1] - '0') * 60 + (s[3] - '0') * 10 + s[4] - '0'; no[i].End = ( (e[0] - '0') * 10 + e[1] - '0') * 60 + (e[3] - '0') * 10 + e[4] - '0'; } for (int i = 1; i < n; ++i) { for (int j = i + 1; j <= n; ++j) { if ( test(no[i].sta, no[i].sta + no[i].last, no[j].sta, no[j].sta + no[j].last) ) { add_edge(i, n + j); add_edge(j, n + i); } if ( test(no[i].sta, no[i].sta + no[i].last, no[j].End - no[j].last, no[j].End) ) { add_edge(i, j); add_edge(n + j, n + i); } if ( test(no[i].End - no[i].last, no[i].End, no[j].sta, no[j].sta + no[j].last) ) { add_edge(n + i, n + j); add_edge(j, i); } if ( test(no[i].End - no[i].last, no[i].End, no[j].End - no[j].last, no[j].End) ) { add_edge(n + i, j); add_edge(n + j, i); } } } scc(); for (int i = 1; i <= n; ++i) { if (cmp[i] == cmp[n + i]) { printf("NO\n"); return 0; } } printf("YES\n"); for (int i = 1; i <= n; ++i) { if (cmp[i] < cmp[n + i]) { printf( "%02d:%02d %02d:%02d\n", no[i].sta / 60, no[i].sta % 60, (no[i].sta + no[i].last) / 60, (no[i].sta + no[i].last) % 60 ); } else { printf( "%02d:%02d %02d:%02d\n", (no[i].End - no[i].last) / 60, (no[i].End - no[i].last) % 60, no[i].End / 60, no[i].End % 60 ); } } return 0; }
相关推荐
Taoist-priest Taoist-priest by nqmy 这些是贫道闲暇时间的做的一些感兴趣的小玩意,以及收集的一些js小插件,其实我更喜欢玩原生的。 1、 这是一个利用canvas,来进行图片切割并上传的工具,对IE的支持不太优秀...
PJBlog3 Priest模板
马修·普里斯特·萨缪尔
用Python编写的高级增量构建系统,引入了对自动依赖性和配方发现的支持。 它支持单线程和多线程构建。 它需要Python v2.6和pybfc,并且本机支持所有POSIX系统。
sprite_character_priest_effect_divineagent.NPK:sprite_character_priest_effect_divineagent.NPK
结果表明:Priest-Zhang算法估算的直径期望是截短值的线性递增函数,修正算法估算的直径期望是截短值的水平线性函数;截短值较小时,2种算法接近,采用前者已能够获得较高精度,纠正截短偏差意义不大;截短值较大时...
斯特拉皮牧师 在mongo db上运行牧师CMS % yarn develop
sprite_character_priest_effect_atbrionac.NPK:sprite_character_priest_effect_atbrionac.NPK
sprite_character_priest_effect_avengerawakening_dash.NPK:sprite_character_priest_effect_avengerawakening_dash.NPK
LocalExchangeUK是Calvin Priest最初为UK LETS团体量身定制的原始Local Exchange源代码的分支。 该软件使用PHP / MySQL编写,为LETS(本地交易系统)组提供了一个交互式网站。 ************************************...
高级java工程师笔试题 詹姆斯·普里斯特 加利福尼亚州洛杉矶 概括 具有 20 年构建 Web 应用程序经验的高级前端/全栈 Web 开发人员。 技能 开发技能 完整的响应式网页设计 网络可访问性和 ...Bootstrap、jQuery、
Native American Warrior Female 01, Native American Warrior Male 01, Native American Warrior Male 02, Native American Warrior Male 03, Priest Male 01, Salesman Male 01, Soldier Male 01, Thug Male 01, ...
指数计划的游戏属性,级别和类别计划的游戏镇 Welcome to Text Adventures You are now on the town of Nee'Peh Here you can: go Tavern - small talk, some Ale and Potions go Aluriel's Priest - here you can ...
尼康优化标准下载。尼康优化标准曲线,相当于游戏刷mod,可用不同机型的曲线,也就是可得不同机型的色彩效果
-Priest:您可以选择另一个玩家并查看他们的卡。 有两张这样的牌,而且它们的价值为 2。 -男爵:你可以选择另一个玩家,然后你再买牌。 谁的价值最低,谁就出局。 在平局的情况下。 两名球员都留下了。 有两张
尼康常用曲线,人像风景原片 直出神器。
游戏角色设计课题 ...2神枪手(Shooter) 子弹的灵魂 30 100 15% 3格斗家(Wrestler) 美女也疯狂 28 100 25% 4魔法师(Priest) 召唤界的女巫 20 100 15% 5圣骑士(paladin ) 用斧头的王者 26 100 25%
这个地方是一片混乱,几乎无法导航,但是他们会发现一个非常有趣的发现:古老的Dragon Priest面具,可以让他们随意在过去和现在之间切换。 目前,那里的废墟除了几处腐烂的法尔默(Falmer)之外几乎是一片荒芜,但...
实用指南的实际内容由Lili David,James Priest和Bernhard Bockelbrink在此资料库之外开发。 如果您想为《实用指南》的改进做出贡献,我们已经建立了[专用页面]( ,其中解释了如何通知我们有关错别字和更正,如何...
priest@johnromanodorazio.com 项目网站 最新发布的 (由于软件包发行版已移至Sourceforge,因此徽章下载计数仅考虑下载。此外,BibleGet网站的下载计数为11,967) 为了安装插件,请从上面的链接下载最新的...