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. 640. Solve the Equation

    class Solution { public: string solveEquation(string equation) { int idx = equation.find('='); , v1 ...

  2. 【Consul】关于健康检查的一点思考

    健康检查是Consul提供的一项主要功能,其配置格式如下: { "check": { "id": "redis", "name&q ...

  3. mysql 导入CSV数据 [转]

    转自: http://blog.chinaunix.net/uid-23284114-id-3196638.html MYSQL   LOAD DATA INFILE命令可以把csv平面文件中的数据导 ...

  4. Java中的原生数据类型

    Java中的原生数据类型(Primitive DataType)共有8种: 1)整型:     使用int表示(32位).2)字节型: 使用byte表示(从-128到127之间的256个整数).3)短 ...

  5. 【APUE】Chapter4 File and Directories

    4.1 Introduction unix的文件.目录都被当成文件来看待(vi也可以编辑目录):我猜这样把一起内容都当成文件的原因是便于统一管理权限这类的内容 4.2 stat, fstat, fst ...

  6. 近期准备发布我的asp.net框架

    此框架为超轻量级架构,适合做中小型的b/s项目

  7. 关于C#数据类型自己的理解

    电脑CUP处理程序的运行.cpu里分为一级缓存,二级缓存,还有三级缓存,之后是内存里的东西. 栈存放在一级缓存里,所以cup调用速度最快,处理起来也效率也最高,但是大小很小,能存放的东西很少. 堆存放 ...

  8. 虚拟现实-VR-UE4-获取UE4

    UE4现在虽然是开源,但是并不是免费的,在你的游戏成功后,回收取5%费用和每个月19美元的费用 所以,第一步,进去UE4官网:https://www.unrealengine.com/zh-CN/wh ...

  9. Lambda表达式在Kotlin中怎样工作的:setOnClickListener的转换(KAD 18)

    作者:Antonio Leiva 时间:Mar 28, 2017 原文链接:https://antonioleiva.com/lambdas-kotlin-android/ 虽然,我在其它文章讲过一点 ...

  10. python3.x 编码问题