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);
}
}
}
}

最新文章

  1. sqlyog重复使用的方法(30天)
  2. iOS 离屏渲染的研究
  3. 普通B/S架构模式同步请求与AJAX异步请求区别(个人理解)
  4. MYSQL里使用正则的速度快还是使用like模糊查询语句快?
  5. PHP 输出图像 imagegif 、imagejpeg 与 imagepng 函数
  6. 就这样获取文件的MD5和大小
  7. 【转】bShare分享插件的使用
  8. maven整合s2sh截图
  9. flex dispatchEvent 实例
  10. 关于bootstrap的datepicker在meteor应用中的使用(不包含bootstrap框架)
  11. 李洪强漫谈iOS开发[C语言-028]-逗号表达式
  12. Object-c学习之路五(@protocol协议)
  13. 解决打包时出现的Failed to verify bitcode
  14. 记事本:CSS
  15. 转 flowcanvas
  16. gearman中worker常驻后台,导致MySQL server has gone away
  17. Android-ProgressDialog点击对话框外部是不让其消失
  18. HashMap几个需要注意的知识点
  19. Java中使用正则表达式获取网页中所有图片的路径
  20. Ctrl+K,Ctrl+D

热门文章

  1. rownum导致sql不能进行谓词推入
  2. [java基础原理] 数字类型原理
  3. Lucene的分词_中文分词器介绍
  4. React &amp; search &amp; keyboard ghost
  5. [luoguP1439] 排列LCS问题(DP + 树状数组)
  6. HUST 1407(数据结构)
  7. JSP内置对象和EL内置对象
  8. SharedPreferences保存用户偏好参数
  9. hdu - 2066 一个人的旅行(基础最短路)
  10. Microsoft Office 2016 for win10 全版本下载+注册激活_Office教程学习网