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 ...
随机推荐
- 8.Python中装饰器是什么?
Python中装饰器是什么? A Python decorator is a specific change that we make in Python syntax to alter functi ...
- mac OS nvm 常用命令
nvm install stable ## 安装最新稳定版 node,当前是node v10.15.0 (npm v6.4.1) nvm install <version> ## 安装指定 ...
- Mysql使用规范及建议
MySQL数据库使用规范一.建表规约1.[强制]表达是与否概念的字段,必须使用is_xxx的方式命名,数据类型是unsigned tinyint (1表示是,0表示否) 说明:任何字段如果为非负数,必 ...
- Get on the CORBA
from: <The Common Object Request Broker: Architecture and Specification> Client To make a requ ...
- ROC-RK3328-CC开源主板运行LibreELEC系统
LibreELEC是运行Kodi媒体中心的轻量级操作系统,基于Linux内核发行,系统为适配Kodi运行环境,做了许多优化和精简,运行速度快,操作简单.是一款很优秀的多功能播放器操作系统. ROC-R ...
- 4.shell基本操作简介
判断一个命令是不是内置命令,可以用type命令 1.printf :冒号 #:〉 test.txt 这里会建立一个空文件test.txt set -o|grep emacs 查看 emacs 模式是 ...
- Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) A Dead Pixel
讨论坏点的左右上下的矩形大小. #include <bits/stdc++.h> using namespace std; int main() { int t; cin >> ...
- CF思维联系--CodeForces -214C (拓扑排序+思维+贪心)
ACM思维题训练集合 Furik and Rubik love playing computer games. Furik has recently found a new game that gre ...
- 树上倍增法求LCA
我们找的是任意两个结点的最近公共祖先, 那么我们可以考虑这么两种种情况: 1.两结点的深度相同. 2.两结点深度不同. 第一步都要转化为情况1,这种可处理的情况. 先不考虑其他, 我们思考这么一个问题 ...
- MySQL命令3
连接 mysql -u username -p 查看进程 SHOW processlist