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 toTi). 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 SiTi and DiSi 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

Source

这个2-sat做的一路蒙蔽

判断个人觉得很简单,

输出解就要命了

有一个小镇上只有一个牧师。这个小镇上有一个传说,

在九月一日结婚的人会受到爱神的保佑,但是要牧师举办一个仪式。

这个仪式要么在婚礼刚刚开始的时候举行,要么举行完婚礼正好结束。 
现在已知有n场婚礼,告诉你每一场的开始和结束时间,

以及举行仪式所需要的时间。问牧师能否参加所有的婚礼,

如果能则输出一种方案。

这题输出解的方法

构建包含2n个点的有向图,如果有a+b则在a和!b   b和!a间连接一条边。

如果a和!a在一个强连通分量中,则无解。要求解集,

只需要将原图缩点后反向建图,然后染色,

具体染色方法是将遇到的第一个没有颜色的点染成红色,与它矛盾的点染成蓝色,

如此循环,所有的红色的点的集合就是解集。

多看点书还是有好处的 ,

这是大佬讲的,理解不了就记忆吧  ,也许这就是弱鸡吧

求大佬给出证明

这题的建图非常简单就没必要讲了

难受啊!!!!

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector> using namespace std;
const int maxn = 4e5 + ;
struct w {
int s, e;
void disp() {
printf("%02d:%02d %02d:%02d\n", s / , s % , e / , e % );
}
} wed[maxn];
struct node {
int u, v, next;
} edge[maxn];
int dfn[maxn], s[maxn], instack[maxn];
int head[maxn], low[maxn], belong[maxn];
int tot, flag, cnt, top, n, m;
void add(int u, int v) {
edge[tot].u = u;
edge[tot].v = v;
edge[tot].next = head[u];
head[u] = tot++;
}
void init() {
tot = flag = top = cnt = ;
memset(dfn, , sizeof(dfn));
memset(head, -, sizeof(head));
memset(instack, , sizeof(head));
memset(s, , sizeof(s));
}
void tarjan(int v) {
low[v] = dfn[v] = ++flag;
instack[v] = ;
s[top++] = v;
for (int i = head[v] ; ~i ; i = edge[i].next ) {
int j = edge[i].v;
if (!dfn[j]) {
tarjan(j);
low[v] = min(low[v], low[j]);
} else if (instack[j]) low[v] = min(low[v], dfn[j]);
}
if (dfn[v] == low[v]) {
cnt++;
int t;
do {
t = s[--top];
instack[t] = ;
belong[t] = cnt;
} while(t != v);
}
} int check(int i, int j) {
if (wed[i].s >= wed[j].e || wed[i].e <= wed[j].s ) return ;
return ;
}
void build(int i, int j) {
if (check( * i, * j)) add( * i, * j + );
if (check( * i, * j + )) add( * i, * j);
if (check( * i + , * j)) add( * i + , * j + );
if (check( * i + , * j + )) add( * i + , * j);
}
int in[maxn];
queue<int>q;
vector<int>tu[maxn];
vector<int>ha[maxn];
int color[maxn];
void maketu() {
int v;
for (int u = ; u < * n ; u++) {
for (int i = head[u] ; ~i ; i = edge[i].next) {
v = edge[i].v;
if (belong[u] != belong[v]) {
tu[belong[v]].push_back(belong[u]);
in[belong[u]]++;
}
}
}
} void topsort() {
for (int i = ; i <= cnt ; i++)
if (!in[i]) q.push(i);
int u, v;
while(!q.empty()) {
u = q.front();
q.pop();
if (!color[u]) {
color[u] = ;
for (int i = ; i < ha[u].size() ; i++)
color[ha[u][i]] = ;
}
for (int i = ; i < tu[u].size() ; i++) {
v = tu[u][i];
in[v]--;
if (!in[v]) q.push(v);
}
}
}
void solve() {
for (int i = ; i < n ; i++) {
if (belong[i << ] == belong[i << | ]) {
printf("NO\n");
return ;
} else {
ha[belong[i << ]].push_back(belong[i << | ]);
ha[belong[i << | ]].push_back(belong[i << ]);
}
}
printf("YES\n");
maketu();
topsort();
for (int i = ; i < n ; i++) {
if (color[belong[i << ]] == ) wed[i << ].disp();
else wed[i << | ].disp();
}
} int main() {
// freopen("DATA.txt", "r", stdin);
scanf("%d", &n);
init();
int x, y, x1, y1, d;
for (int i = ; i < n ; i++) {
scanf("%d:%d %d:%d %d", &x, &y, &x1, &y1, &d);
wed[i << ].s = x * + y;
wed[i << ].e = wed[i << ].s + d;
wed[i << | ].e = x1 * + y1;
wed[i << | ].s = wed[i << | ].e-d;
}
for (int i = ; i < n ; i++)
for (int j = ; j < n ; j++)
if (i != j) build(i, j);
for (int i = ; i < * n ; i++)
if (!dfn[i]) tarjan(i);
solve();
return ;
}

poj3683 2-sat Priest John's Busiest Day的更多相关文章

  1. 【POJ3683】Priest John's Busiest Day

    题目 John is the only priest in his town. September 1st is the John's busiest day in a year because th ...

  2. POJ 3683 Priest John's Busiest Day / OpenJ_Bailian 3788 Priest John's Busiest Day(2-sat问题)

    POJ 3683 Priest John's Busiest Day / OpenJ_Bailian 3788 Priest John's Busiest Day(2-sat问题) Descripti ...

  3. 图论(2-sat):Priest John's Busiest Day

    Priest John's Busiest Day   Description John is the only priest in his town. September 1st is the Jo ...

  4. poj 3686 Priest John's Busiest Day

    http://poj.org/problem?id=3683 2-sat 问题判定,输出一组可行解 http://www.cnblogs.com/TheRoadToTheGold/p/8436948. ...

  5. POJ 3683 Priest John's Busiest Day (2-SAT)

    Priest John's Busiest Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6900   Accept ...

  6. POJ 3683 Priest John's Busiest Day(2-SAT+方案输出)

    Priest John's Busiest Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10010   Accep ...

  7. Priest John's Busiest Day(POJ 3683)

    原题如下: Priest John's Busiest Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12162   ...

  8. POJ3683 Priest John's Busiest Day(2-SAT)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11049   Accepted: 3767   Special Judge ...

  9. POJ3683 Priest John's Busiest Day 【2-sat】

    题目 John is the only priest in his town. September 1st is the John's busiest day in a year because th ...

随机推荐

  1. unity独立游戏开发日记2018/09/27

    今天优化了下昨天的代码,并且添加了树木和其他资源的生成.还修复了接近石头后,挖掘图标不出现的bug.目前可以在unity中稳定60-70fps. 详看文章:https://www.cnblogs.co ...

  2. C语言实例解析精粹学习笔记——42(插入排序)

    实例说明: 将一个整数数组按从小到大的顺序进行排序.(主要学习基本的插入排序和改进的冒泡排序的算法和应用) 思路1: 从第一个数据开始,分别比较其后的数据,若比它小,则将这两个数的位置交换:从第一个数 ...

  3. linux-课题练习1

    1.创建组testgroup: 2.创建用户a2012,先采用默认设置创建,然后使该用户加入testgroup组. 3.创建用户a2013,其用户主目录为/tmp/a2013,其主组为testgrou ...

  4. R语言学习笔记(十五):获取文件和目录信息

    file.info() 参数是表示文件名称的字符串向量,函数会给出每个文件的大小.创建时间.是否为目录等信息. > file.info("z.txt") size isdir ...

  5. dijkstra算法学习

    dijkstra算法学习 一.最短路径 单源最短路径:计算源点到其他各顶点的最短路径的长度 全局最短路径:图中任意两点的最短路径 Dijkstra.Bellman-Ford.SPFA求单源最短路径 F ...

  6. iOS笔记058 - IOS之多线程

    IOS开发中多线程 主线程 一个iOS程序运行后,默认会开启1条线程,称为"主线程"或"UI线程" 作用 显示和刷新界面 处理UI事件(点击.滚动.拖拽等) 注 ...

  7. HDU 4719 Oh My Holy FFF(DP+线段树)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)

    Description N soldiers from the famous "*FFF* army" is standing in a line, from left to ri ...

  8. [译]如何撤销git仓库里的所有修改?

    原文来源:https://stackoverflow.com/questions/29007821/git-checkout-all-the-files 问: 如何撤销我在我git仓库所做的所有修改? ...

  9. Mybatis学习系列(七)缓存机制

    Mybatis缓存介绍 MyBatis提供一级缓存和二级缓存机制. 一级缓存是Sqlsession级别的缓存,Sqlsession类的实例对象中有一个hashmap用于缓存数据.不同的Sqlsessi ...

  10. servletContext的定义