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. http2提升效率的几个点

    1.二进制传输,消息的解析效率更高 2.头部数据压缩,传输效率更高 3.多路复用,可以让请求并发执行 4.服务器推送,可以主动推送数据到浏览器 http2加载图片demo:https://http2. ...

  2. CURL PHP模拟浏览器get和post

    模拟浏览器get和post数据需要经常用到的类, 在这里收藏了几个不错的方法 方法一 <?php define ( 'IS_PROXY', true ); //是否启用代理 /* cookie文 ...

  3. UVa 11998 破碎的键盘(数组实现链表)

    题意: 输入一行字符,其中包含'[' 和 ‘]’, 意思为键盘上的home 和 end 键, 然后模拟字符在键盘上输入. 输入一行最终的结果 分析: 用数组模拟一个链表, 在链表的头尾插入字母然后输出 ...

  4. 32道常见的Java基础面试题

    1. 什么是 Java 虚拟机(JVM)?为什么 Java 被称作是“平台无关的编程语言”? Java 虚拟机是一个可以执行 Java 字节码的虚拟机进程.Java 源文件被编译成能被 Java 虚拟 ...

  5. 【Codeforces 492D】Vanya and Computer Game

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 第一个人攻击一次需要1/x秒 第二个人攻击一次需要1/y秒 这两个数字显然都是小数. 我们可以二分最后用了多少时间来攻击. 显然这个是有单调性 ...

  6. 九度oj 题目1180:对称矩阵

    题目1180:对称矩阵 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3092 解决:1607 题目描述: 输入一个N维矩阵,判断是否对称. 输入: 输入第一行包括一个数:N(1<= ...

  7. j简单的分类实现-K近邻

          dataSetSize=dataSet.shape[0]                          voteIlabel=labels[sortedDistIndicies[i]] ...

  8. node.js 写流 createWriteStream----由浅入深

    createWriteStream 写流 基于fs模块 let fs=require("fs"); createWriteStream创建一个写流 我们先创建一个2.txt要写入的 ...

  9. Linux下汇编语言学习笔记20 ---

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

  10. 51 nod 1007 正整数分组 (简单01背包) && csu 1547: Rectangle

    http://www.51nod.com/onlineJudge/questionCode.html#problemId=1007&noticeId=15020 求出n个数的和sum,然后用s ...