博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Poj 3683 Priest John's Busiest Day(2-SAT)
阅读量:6830 次
发布时间:2019-06-26

本文共 3210 字,大约阅读时间需要 10 分钟。

Poj 3683 Priest John's Busiest Day(2-SAT)

Priest John's Busiest DayTime Limit: 2000MS      Memory Limit: 65536KTotal Submissions: 9874     Accepted: 3381      Special JudgeDescriptionJohn 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.InputThe 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.OutputThe 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 Input208:00 09:00 3008:15 09:00 20Sample OutputYES08:00 08:3008:40 09:00

2-SAT的重点就在于建图,对于此题,显然每个时间段我们只能选择前D[i]时间或者后D[i]段时间,我们根据每两队时间限制进行连边,例如

min(S[i]+D[i],S[j]+D[j])>max(S[i],S[j]),我们只能选择其中之一在前半段,另一个在后半段了,这样建了一个新图后,我们求其强连通分量。如果一个时间的前半段和后半段在同一个强联通分量中,很显然出现了矛盾,此时无解。而输出答案时我们需要利用到一个结论:
x所在的强连通分量的拓扑序在!x所在的强连通分量的拓扑序之后,则x为真。
这个结论是充要的,所以反之亦然。

#include 
#include
#include
#include
#include
#include
#include
#include
#define ll long long#define inf 1000000000LL#define mod 1000000007using namespace std;int read(){ int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*f;}const int N=2e3+10;int S[N],T[N],D[N];vector
G[N]; //图vector
rG[N]; //反向图vector
vs; //后序遍历的顶点列表bool vis[N];int cmp[N]; //所属强连通分量的拓扑序int sum[N];int n,tn;void Addedge(int from,int to){ G[from].push_back(to); rG[to].push_back(from);}void dfs(int v){ vis[v]=true; for(int i=0;i
=0;i--){ if(!vis[vs[i]]) rdfs(vs[i],k++); //遍历每个联通分量的点集 } return k;}int cacu(char *str){ int tmp=0,h[2],top=0; for(int j=0;j
max(S[i],S[j])){ Addedge(i,tn+j); Addedge(j,tn+i); } if(min(S[i]+D[i],T[j])>max(S[i],T[j]-D[j])){ Addedge(i,j); Addedge(tn+j,tn+i); } if(min(T[i],S[j]+D[j])>max(T[i]-D[i],S[j])){ Addedge(tn+i,tn+j); Addedge(j,i); } if(min(T[i],T[j])>max(T[i]-D[i],T[j]-D[j])){ Addedge(tn+i,j); Addedge(tn+j,i); } } }}int main(){ tn=read(); char str1[20],str2[20]; for(int i=0;i
cmp[tn+i]){ printf("%02d:%02d %02d:%02d\n",S[i]/60,S[i]%60,(S[i]+D[i])/60,(S[i]+D[i])%60); }else{ printf("%02d:%02d %02d:%02d\n",(T[i]-D[i])/60,(T[i]-D[i])%60,T[i]/60,T[i]%60); } } return 0;}

转载于:https://www.cnblogs.com/zsyacm666666/p/6808963.html

你可能感兴趣的文章
ubuntu14.04 qt4 C++开发环境搭建
查看>>
iOS 通讯录-获取联系人属性
查看>>
HTML5 文件域+FileReader 读取文件(一)
查看>>
不要让你的未来,现在恨自己
查看>>
jquery表单验证
查看>>
使用 Jasmine 进行测试驱动的 JavaScript 开发
查看>>
[CareerCup] 8.2 Call Center 电话中心
查看>>
GestureDetector和SimpleOnGestureListener的使用教程
查看>>
【FFmpeg】Windows下FFmpeg编译
查看>>
sqlserver字段类型详解
查看>>
Java多线程16:线程组
查看>>
ubuntu wireshark找不到网卡及开启IP转发
查看>>
波音公司开发最轻金属 99.99%是空气
查看>>
Python执行效率测试模块timei的使用方法与与常用Python用法的效率比较
查看>>
TextureView+SurfaceTexture+OpenGL ES来播放视频(二)
查看>>
adadmin: error while loading shared libraries: libclntsh.so.10.1
查看>>
模式匹配KMP算法
查看>>
《Android开发艺术探索》读书笔记 (2) 第2章 IPC机制
查看>>
学习 easyui 之一:easyloader 分析与使用
查看>>
大页内存(HugePages)
查看>>