Priest John's Busiest Day
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 11127   Accepted: 3785   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

Source

将每个时间段拆分成两个 就变成的2-sat模型
利用拓扑排序+染色输出任意方案就可以了
注意数组大小
 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#include<string.h>
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const int INF=0x3f3f3f3f;
const double eps=0.0000000001;
const int N=+;
const ll mod=1e9+;
struct Node{
int x,y;
}a[N];
struct node{
int to,next;
}edge[N*N];
struct NODE{
int to,next;
}Edge[N*N];
int Head[N];
int head[N],low[N],dfn[N];
int vis[N*],belong[N*];
int opp[N*];
int cnt,t,tot;
stack<int>st;
void init(){
tot=;
t=;
cnt=;
memset(belong,-,sizeof(belong));
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
memset(vis,,sizeof(vis));
memset(head,-,sizeof(head));
}
void add(int u,int v){
edge[tot].to=v;
edge[tot].next=head[u];
head[u]=tot++;
}
void ADD(int u,int v){
Edge[tot].to=v;
Edge[tot].next=Head[u];
Head[u]=tot++;
}
void tarjan(int u){
vis[u]=;
st.push(u);
dfn[u]=low[u]=++t;
for(int i=head[u];i!=-;i=edge[i].next){
int v=edge[i].to;
if(dfn[v]==){
tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(vis[v]){
low[u]=min(low[u],dfn[v]);
}
}
if(low[u]==dfn[u]){
cnt++;
int vv;
do{
vv=st.top();
st.pop();
belong[vv]=cnt;
vis[vv]=;
}while(vv!=u);
}
}
int n;
int in[N];
void topsort(){
queue<int>q;
memset(vis,,sizeof(vis));
for(int i=;i<=cnt;i++)if(in[i]==)q.push(i);
while(q.empty()==){
int u=q.front();
q.pop();
if(vis[u]==){
vis[u]=;
vis[opp[u]]=-;
}
for(int i=Head[u];i!=-;i=Edge[i].next){
int v=Edge[i].to;
in[v]--;
if(in[v]==){
q.push(v);
}
}
}
}
int check(int i,int j){
if(a[i].y<=a[j].x){
return ;
} if(a[i].x>=a[j].y){
return ;
}
return ;
}
char str1[];
char str2[];
int main(){
while(scanf("%d",&n)!=EOF){
int val;
init();
memset(in,,sizeof(in));
for(int i=;i<(n<<);i=i+){
scanf("%s%s%d",str1,str2,&val);
int x=(str1[]-'')**+(str1[]-'')*+(str1[]-'')*+str1[]-'';
int y=(str2[]-'')**+(str2[]-'')*+(str2[]-'')*+str2[]-'';;
a[i].x=x;
a[i].y=x+val;
a[i+].x=y-val;
a[i+].y=y;
}
for(int i=;i<(n<<);i=i+){
for(int j=;j<(n<<);j=j+){
if(i==j)continue;
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);
}
}
for(int i=;i<(n<<);i++){
if(dfn[i]==)tarjan(i);
}
int flag=;
for(int i=;i<(n<<);i=i+){
opp[belong[i]]=belong[i^];
opp[belong[i^]]=belong[i];
if(belong[i]==belong[i^])flag=;
}
if(flag){
cout<<"NO"<<endl;
continue;
}
cout<<"YES"<<endl;
memset(Head,-,sizeof(Head));
tot=;
for(int u=;u<(n<<);u++){
for(int i=head[u];i!=-;i=edge[i].next){
int v=edge[i].to;
if(belong[u]!=belong[v]){
ADD(belong[v],belong[u]);
in[belong[u]]++;
}
}
} topsort();
int aa,b,c,d;
for(int i=;i<n;i++){
if(vis[belong[i<<]]==){
aa=a[i*].x/;
b=a[i*].x%;
c=a[i*].y/;
d=a[i*].y%;
//cout<<a[i*2].x<<" "<<a[i*2].y<<endl;
printf("%02d:%02d %02d:%02d\n",aa,b,c,d);
}
else{
aa=a[i*+].x/;
b=a[i*+].x%;
c=a[i*+].y/;
d=a[i*+].y%;
//cout<<a[i*2+1].x<<" "<<a[i*2+1].y<<endl;
printf("%02d:%02d %02d:%02d\n",aa,b,c,d);
}
}
}
}

poj 3683(2-sat+拓扑排序)的更多相关文章

  1. POJ 2367 (裸拓扑排序)

    http://poj.org/problem?id=2367 题意:给你n个数,从第一个数到第n个数,每一行的数字代表排在这个行数的后面的数字,直到0. 这是一个特别裸的拓扑排序的一个题目,拓扑排序我 ...

  2. poj 3687 Labeling Balls(拓扑排序)

    题目:http://poj.org/problem?id=3687题意:n个重量为1~n的球,给定一些编号间的重量比较关系,现在给每个球编号,在符合条件的前提下使得编号小的球重量小.(先保证1号球最轻 ...

  3. [ACM] POJ 3687 Labeling Balls (拓扑排序,反向生成端)

    Labeling Balls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10161   Accepted: 2810 D ...

  4. poj 2762(强连通分量+拓扑排序)

    题目链接:http://poj.org/problem?id=2762 题意:给出一个有向图,判断任意的两个顶点(u,v)能否从u到达v,或v到达u,即单连通,输出Yes或No. 分析:对于同一个强连 ...

  5. POJ 2585.Window Pains 拓扑排序

    Window Pains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1888   Accepted: 944 Descr ...

  6. POJ 1270 Following Orders 拓扑排序

    http://poj.org/problem?id=1270 题目大意: 给你一串序列,然后再给你他们部分的大小,要求你输出他们从小到大的所有排列. 如a b f g 然后 a<b ,b< ...

  7. POJ 1270 Following Orders (拓扑排序,dfs枚举)

    题意:每组数据给出两行,第一行给出变量,第二行给出约束关系,每个约束包含两个变量x,y,表示x<y.    要求:当x<y时,x排在y前面.让你输出所有满足该约束的有序集. 思路:用拓扑排 ...

  8. POJ 1128 Frame Stacking (拓扑排序)

    题目链接 Description Consider the following 5 picture frames placed on an 9 x 8 array. ........ ........ ...

  9. Poj 2367 Genealogical tree(拓扑排序)

    题目:火星人的血缘关系,简单拓扑排序.很久没用邻接表了,这里复习一下. import java.util.Scanner; class edge { int val; edge next; } pub ...

  10. POJ 1094 (传递闭包 + 拓扑排序)

    题目链接: POJ 1094 题目大意:有 1 ~ N 个大写字母,且从 A 开始依次 N 个.再给你 M 个小于的关系,比如 A < B ,让你判断三种可能: 1.在第 i 个关系罗列之后,是 ...

随机推荐

  1. javascript事件委托和jquery事件委托

    元旦过后,新年第一篇. 初衷:很多的面试都会涉及到事件委托,前前后后也看过好多博文,写的都很不错,写的各有千秋,自己思前想后,为了以后自己的查看,也同时为现在找工作的前端小伙伴提供一个看似更全方位的解 ...

  2. mysql基准测试与sysbench工具

    一.基准测试简介  1.什么是基准测试 数据库的基准测试是对数据库的性能指标进行定量的.可复现的.可对比的测试. 基准测试与压力测试 基准测试可以理解为针对系统的一种压力测试.但基准测试不关心业务逻辑 ...

  3. About SQL Server 2016 CPT2

    SQL Server 2016 CTP2已经发布,可以从以下主页进行下载. http://www.microsoft.com/en-us/server-cloud/products/sql-serve ...

  4. noip模拟赛 单词

    分析:这道题真心难想.最主要的是怎么样不重复. 为了不重复统计,把所有符合条件的单词分成两类,一类是某些单词的前缀,一类是 不是任何单词的前缀.涉及到前缀后缀,维护两个trie树,处理3个数组a,b, ...

  5. noip模拟赛 残

    分析:这道题有点丧病啊......斐波那契数列本来增长就快,n <= 10^100又套2层,看到题目就让人绝望.不过这种题目还是有套路的.首先求斐波那契数列肯定要用到矩阵快速幂,外层的f可以通过 ...

  6. Eclipse4.5在线安装Aptana插件及配置代码提示教程

    一.Aptana插件官网地址         我在网上试过登陆到aptana官网后点击下载,选择下载eclipse插件版,然后页面给出一串地址:http://download.aptana.com/s ...

  7. Linux下汇编语言学习笔记6 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  8. Oldboy 基于Linux的C/C++自动化开发---MYSQL

    http://www.eimhe.com/forum.php?mod=viewthread&tid=142952#lastpost http://www.eimhe.com/thread-14 ...

  9. systemtap 作用-- SystemTap使用技巧

    http://blog.csdn.net/wangzuxi/article/details/42849053

  10. Windows Socket IO 模型

    http://www.cppblog.com/huangwei1024/archive/2010/11/22/134205.html