poj3683 2-SAT 同上一道
| Time Limit: 2000MS | Memory Limit: 65536K | |||
| Total Submissions: 10151 | Accepted: 3475 | 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
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int N=;
struct node{
int st,ed;
}e[N];
int dfn[N],low[N],bl[N],in[N],q[N],col[N],con[N];
bool instack[N];
int cnt,scnt,l,n;
vector<int>v[N];
vector<int>g[N];
void init(){
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(in));
memset(col,,sizeof(col));
memset(instack,,sizeof(instack));
for(int i=;i<=*n;++i) v[i].clear(),g[i].clear();
cnt=scnt=l=;
}
inline void add(int a,int b){v[a].push_back(b);}
void Tarjan(int u){
low[u]=dfn[u]=++cnt;
q[l++]=u;
instack[u]=;
for(int i=;i<(int)v[u].size();++i){
int x=v[u][i];
if(!dfn[x]){
Tarjan(x);
low[u]=min(low[u],low[x]);
}
else if(instack[x]&&dfn[x]<low[u]) low[u]=dfn[x];
}
if(low[u]==dfn[u]){
int t;++scnt;
do{
t=q[--l];
instack[t]=;
bl[t]=scnt;
}while(t!=u);
}
}
void rebuild(){
for(int i=;i<*n;++i) for(int j=;j<(int)v[i].size();++j){
int a=bl[i],b=bl[v[i][j]];
if(a==b) continue;
++in[a];
g[b].push_back(a);
}
}
void topsort(){
queue<int>Q;
for(int i=;i<=scnt;++i) if(!in[i]) Q.push(i);
while(!Q.empty()){
int u=Q.front();
Q.pop();
if(!col[u]) {
col[u]=;
col[con[u]]=;
}
for(int i=;i<(int)g[u].size();++i){
int x=g[u][i];
--in[x];
if(in[x]==) Q.push(x);
}
}
}
void solve(){
for(int i=;i<*n;++i) if(!dfn[i]) Tarjan(i);
for(int i=;i<n;++i) {
if(bl[*i]==bl[*i+]) {puts("NO");return;}
int a=bl[*i],b=bl[*i+];
con[a]=b;con[b]=a;
}
rebuild();
topsort();
puts("YES");
for(int i=;i<*n;i+=){
if(col[bl[i]]==) {
int h1=e[i].st/,m1=e[i].st%,h2=e[i].ed/,m2=e[i].ed%;
printf("%02d:%02d %02d:%02d\n",h1,m1,h2,m2);
}
else {
int h1=e[i^].st/,m1=e[i^].st%,h2=e[i^].ed/,m2=e[i^].ed%;
printf("%02d:%02d %02d:%02d\n",h1,m1,h2,m2);
}
}
}
int getx(char *s){
int h,m;
h=(s[]-'')*+s[]-'';
m=(s[]-'')*+s[]-'';
return h*+m;
}
bool Ju(const node &a,const node &b){
if (b.st>=a.st && b.st < a.ed) return ;
if(a.st>=b.st && a.st < b.ed) return ;
return ;
}
int main(){
char st[],ed[];
int time;
while(scanf("%d",&n)!=EOF){
init();
for(int i=;i<n;++i){
scanf("%s %s %d",st,ed,&time);
e[*i].st=getx(st);e[*i].ed=getx(st)+time;
e[*i+].st=getx(ed)-time;e[*i+].ed=getx(ed);
}
for(int i=;i<*n;++i)
for(int j=i+;j<*n;++j){
if(i==(j^)) continue;
if(Ju(e[i],e[j])) {add(i,j^);add(j,i^);}
}
solve();
}
}
YES
08:00 08:30
08:40 09:00
poj3683 2-SAT 同上一道的更多相关文章
- poj3683 2 -sat输出路径
tarjan缩点,拓扑排序染色输出(貌似挑战上面没有拓扑啊,而且这样写还过了= =) 主要是找s,t,d,三者之间的关系,找出合取范式这题就很容易了 #include<map> #incl ...
- S - 骨牌铺方格(第二季水)
Description 在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数. 例如n=3时,为2× 3方格,骨牌的铺放方案有三种, ...
- zzuli 1875多线DP
1875: 蛤玮的财宝 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 530 Solved: 116 SubmitStatusWeb Board De ...
- ZJOI2019Round#1
考的这么差二试基本不用去了 不想说什么了.就把这几天听课乱记的东西丢上来吧 这里是二试乱听课笔记ZJOI2019Round#2 ZJOI Round#1 Day1 M.<具体数学>选讲 罗 ...
- POJ 3678 Katu Puzzle(2 - SAT) - from lanshui_Yang
Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a ...
- 【一天一道LeetCode】#349. Intersection of Two Arrays
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...
- 【一天一道LeetCode】#165. Compare Version Numbers
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 来源: htt ...
- 【一天一道LeetCode】#84. Largest Rectangle in Histogram
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given n ...
- 【一天一道LeetCode】#54. Spiral Matrix
一天一道LeetCode系列 (一)题目 Given a matrix of m x n elements (m rows, n columns), return all elements of th ...
随机推荐
- Java和php中的try-catch分析
为什么80%的码农都做不了架构师?>>> 描述:对一个健壮的系统来讲,异常处理是必不可少的一部分,针对异常的管理,主要就是异常的捕获和处理操作,然而在php中使用try-catc ...
- Linux指令面试题01-进程查看与终止
查看某一进程是否运行:ps -ef|grep 程序名 终止程序: kill pid 转载于:https://www.cnblogs.com/feihujiushiwo/p/10896636.html
- nginx 反向代理转发导致css,js,图片失效
为什么80%的码农都做不了架构师?>>> 需要添加以下配置 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { proxy_pass htt ...
- 数学--数论--Hdu 1452 Happy 2004(积性函数性质+和函数公式+快速模幂+乘法逆元)
Consider a positive integer X,and let S be the sum of all positive integer divisors of 2004^X. Your ...
- POJ 2230 Watchcow 欧拉回路的DFS解法(模板题)
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 9974 Accepted: 4307 Special Judg ...
- Spring源码阅读 之 配置的读取,解析
在上文中我们已经知道了Spring如何从我们给定的位置加载到配置文件,并将文件包装成一个Resource对象.这篇文章我们将要探讨的就是,如何从这个Resouce对象中加载到我们的容器?加载到容器后又 ...
- 201771010113 李婷华 《面向java对象程序设计(Java)》第四章学习总结
一. 理论知识部分 第四章 对象与类 本章主要讲述面向对象程序设计.如何创建标准Java类库中的类对象.如何编写自己的类. 1.面向对象程序设计的几个主要概念: 抽象数据类型.类和对象.封装.类层次( ...
- 在培训机构花了好几万学Java,当了程序员还常被鄙视,这是招谁惹谁了?
在之前的文章中说过,我是非计算机专业,通过参加培训进入程序员这行的. 入了程序员这行后,挺长一段时间在亲戚朋友中,我还是挺有面子的:家族里的第一个程序员,工作不用风吹日晒,收入比其他行业高不少,尤其是 ...
- [uva_la7146 Defeat the Enemy(2014 shanghai onsite)]贪心
题意:我方n个军队和敌方m个军队进行一对一的对战,每个军队都有一个攻击力和防御力,只要攻击力不小于对方就可以将对方摧毁.问在能完全摧毁敌方的基础上最多能有多少军队不被摧毁. 思路:按防御力从大到小考虑 ...
- 瞬间教你学会使用java中list的retainAll方法
retainAll方法简介 当我们有两个list集合的时候,我们可以使用retainAll方法求得两个list集合的子集.retainAll是Collection接口中提供的一个方法,各个实现类有自己 ...