poj3683 2-sat Priest John's Busiest Day
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 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
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的更多相关文章
- 【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 ...
 - 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 ...
 - 图论(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 ...
 - poj 3686 Priest John's Busiest Day
		
http://poj.org/problem?id=3683 2-sat 问题判定,输出一组可行解 http://www.cnblogs.com/TheRoadToTheGold/p/8436948. ...
 - POJ  3683  Priest John's Busiest Day (2-SAT)
		
Priest John's Busiest Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6900 Accept ...
 - POJ 3683 Priest John's Busiest Day(2-SAT+方案输出)
		
Priest John's Busiest Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10010 Accep ...
 - Priest John's Busiest Day(POJ 3683)
		
原题如下: Priest John's Busiest Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12162 ...
 - POJ3683 Priest John's Busiest Day(2-SAT)
		
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11049 Accepted: 3767 Special Judge ...
 - 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 ...
 
随机推荐
- JavaScript实现判断图片是否加载完成的3种方法整理
			
JavaScript实现判断图片是否加载完成的3种方法整理 有时候我们在前端开发工作中为了获取图片的信息,需要在图片加载完成后才可以正确的获取到图片的大小尺寸,并且执行相应的回调函数使图片产生某种显示 ...
 - c++实验3类和对象
			
实 验 3: part 1:验证 part 2:graph #include <iostream> #include "graph.h" using namespac ...
 - vuex的使用及持久化state的方式详解
			
vuex的使用及持久化state的方式详解 转载 更新时间:2018年01月23日 09:09:37 作者:baby格鲁特 我要评论 这篇文章主要介绍了vuex的使用及持久化state的方 ...
 - Apache 配置说明
			
ServerRoot ServerRoot: The top of the directory tree under which the server's configuration, error, ...
 - mysql连接jdbc查询代码
			
package com.answer.test; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.S ...
 - LaTeX工具——mathpix安利
			
官网: https://mathpix.com/ 效果看下图: 图片打不开点这里 识别效果还行,感觉很适合jbc/zcy这种不喜欢打LaTex公式的神仙.
 - swagger webapi控制器注释不显示
			
swagger是webapi文档描述及调试工具,要在asp.net mvc中使用swagger,需要安装Swashbuckle.Core这个包,安装好后会在app_start中生成SwaggerCon ...
 - ionic 入口禁止加载其他页面
			
.state('memberOrders', { prefetchTemplate: false, url: '/memberOrders', templateUrl: '/MemberOrders' ...
 - 「日常训练」「小专题·图论」 Cow Contest (1-3)
			
题意 分析 问题是要看出来这是个floyd闭包问题.我没看出来- - 分析之后补充. 代码 // Origin: // Theme: Graph Theory (Basic) // Date: 080 ...
 - npx 命令介绍
			
这个是在 npmv5.2.0引入的一条命令(查看),引入这个命令的目的是为了提升开发者使用包内提供的命令行工具的体验. 为什么引入这个命令 举个例子,我们开发中要运行 parcel 命令来打包:par ...