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 ...
随机推荐
- Springboot中,Tomcat启动war包的流程
将一个SpringBoot项目,打成war包 <!-- 1. 修改POM依赖 --> <dependency> <groupId>org.springframewo ...
- log4j MDC NDC详解
NDC ( Nested Diagnostic Context )和 MDC ( Mapped Diagnostic Context )是 log4j 种非常有用的两个类,它们用于存储应用程序的上下文 ...
- Vue.js 条件渲染 v-if、v-show、v-else
v-if v-if 完全根据表达式的值在DOM中生成或移除一个元素.如果v-if表达式赋值为false,那么对应的元素就会从DOM中移除:否则,对应元素的一个克隆将被重新插入DOM中. 1 2 3 ...
- Linux 查看进程资源--ps、top命令
1,ps命令 ps能够给出当前系统中进程的快照.它能捕获系统在某一事件的进程状态 命令参数: a 显示所有进 ...
- C语言编程入门题目--No.14
题目:将一个正整数分解质因数.例如:输入90,打印出90=233*5. 程序分析:对n进行分解质因数,应先找到一个最小的质数k,然后按下述步骤完成: (1)如果这个质数恰等于n,则说明分解质因数的过程 ...
- LCA 学习总结
怎么说,LCA裸题直接套板子,大家都会做,这样的题没必要看,剩下的题发先LCA只是一个工具就像是搜索一样,只是一个工具而不是一种算法,所以借助这套工具在其图论问题如最长路,数据结构等问题上再去发挥作用 ...
- P4370 [Code+#4]组合数问题2
题目要求当\(0\leq a\leq b\leq n\)时,\(k\)个\(\tbinom{b}{a}\)的和的最大值 观察杨辉三角形,可以发现,最大的\(\tbinom{b}{a}\),为\(\tb ...
- python(文件操作)
一.文件操作 1.tell()方法返回文件的当前位置,即文件指针当前位置. UTF-8 编码格式,一个中文占3个字符 GBK 编码格式,一个中文占2个字符 #写入前文件内容如下 "" ...
- ubuntu16 安装redis
ubuntu16 安装redis并开机自启 1.redis-3.2.5.tar.gz解压到/usr/local下 tar -xvf redis-3.2.5.tar.gz 2.进入源码包/usr/loc ...
- file download hash mismatch
在linux中使用cmake时,遇到了"file download hash mismatch",同时status显示"unsupported protocol" ...