Poj3683:Priest John's Busiest Day
题意
n对夫妻要结婚,第i对夫妻结婚的婚礼持续时间为[Si, Ti],他们会举行一个仪式,仪式时间为Di,这个仪式只能举行在开头或者结尾举行,要么[Si, Si+Di],要么[Ti-Di, Ti],然而举行仪式的牧师只有一个,问牧师能否举行完所有仪式
按输入顺序输出方案
手动翻译
Sol
\(2-SAT\)输出一组可行解
这个很烦
\(Tarjan\)缩点成\(DAG\)后再拓扑排序+染色
只传递不选的标记
# include <iostream>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <math.h>
# include <algorithm>
# include <queue>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(2005);
const int __(2e6 + 5);
IL int Input(){
RG int x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
}
int n, first[_], head[_], cnt, num, s[_], t[_], d[_], cho[_];
int S[_], vis[_], dfn[_], low[_], Index, col[_], deg[_], oth[_];
struct Edge{
int to, next;
} edge[__], dag[__];
queue <int> Q;
IL void Add(RG int u, RG int v){
edge[cnt] = (Edge){v, first[u]}, first[u] = cnt++;
}
IL void Add_DAG(RG int u, RG int v){
dag[cnt] = (Edge){v, head[u]}, head[u] = cnt++, ++deg[v];
}
IL void Tarjan(RG int u){
vis[u] = 1, dfn[u] = low[u] = ++Index, S[++S[0]] = u;
for(RG int e = first[u]; e != -1; e = edge[e].next){
RG int v = edge[e].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(dfn[u] != low[u]) return;
RG int v = S[S[0]--]; col[v] = ++num, vis[v] = 0;
while(v != u) v = S[S[0]--], col[v] = num, vis[v] = 0;
}
IL void Dfs(RG int u){
if(cho[u] != -1) return;
cho[u] = 0;
for(RG int e = head[u]; e != -1; e = dag[e].next) Dfs(dag[e].to);
}
IL int GetTime(){
return Input() * 60 + Input();
}
IL void OutTime(RG int x){
printf("%.2d:%.2d ", x / 60, x % 60);
}
IL int Cross(RG int l1, RG int r1, RG int l2, RG int r2){
if(l1 > l2) swap(l1, l2), swap(r1, r2);
return r1 > l2;
}
int main(RG int argc, RG char* argv[]){
n = Input(), Fill(first, -1), Fill(head, -1), Fill(cho, -1);
for(RG int i = 1; i <= n; ++i)
s[i] = GetTime(), t[i] = GetTime(), d[i] = Input();
for(RG int i = 1; i < n; ++i)
for(RG int j = i + 1; j <= n; ++j){
if(Cross(s[i], s[i] + d[i], s[j], s[j] + d[j])) Add(i, j + n), Add(j, i + n);
if(Cross(s[i], s[i] + d[i], t[j] - d[j], t[j])) Add(i, j), Add(j + n, i + n);
if(Cross(t[i] - d[i], t[i], s[j], s[j] + d[j])) Add(i + n, j + n), Add(j, i);
if(Cross(t[i] - d[i], t[i], t[j] - d[j], t[j])) Add(i + n, j), Add(j + n, i);
}
RG int tmp = n << 1; cnt = 0;
for(RG int i = 1; i <= tmp; ++i) if(!dfn[i]) Tarjan(i);
for(RG int i = 1; i <= n; ++i){
if(col[i] == col[i + n]) return puts("NO"), 0;
oth[col[i]] = col[i + n], oth[col[i + n]] = col[i];
}
puts("YES");
for(RG int i = 1; i <= tmp; ++i)
for(RG int e = first[i]; e != -1; e = edge[e].next)
if(col[i] != col[edge[e].to]) Add_DAG(col[edge[e].to], col[i]);
for(RG int i = 1; i <= num; ++i) if(!deg[i]) Q.push(i);
while(!Q.empty()){
RG int u = Q.front(); Q.pop();
if(cho[u] != -1) continue;
cho[u] = 1, Dfs(oth[u]);
for(RG int e = head[u]; e != -1; e = dag[e].next)
if(!--deg[dag[e].to]) Q.push(dag[e].to);
}
for(RG int i = 1; i <= n; ++i){
if(cho[col[i]]) OutTime(s[i]), OutTime(s[i] + d[i]);
else OutTime(t[i] - d[i]), OutTime(t[i]);
puts("");
}
return 0;
}
Poj3683:Priest John's Busiest Day的更多相关文章
- 【POJ3683】Priest John's Busiest Day
题目 John is the only priest in his town. September 1st is the John's busiest day in a year because th ...
- 图论(2-sat):Priest John's Busiest Day
Priest John's Busiest Day Description John is the only priest in his town. September 1st is the Jo ...
- poj3683 2-sat Priest John's Busiest Day
Description John is the only priest in his town. September 1st is the John's busiest day in a year b ...
- Priest John's Busiest Day(POJ 3683)
原题如下: Priest John's Busiest Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12162 ...
- POJ 3683 Priest John's Busiest Day / OpenJ_Bailian 3788 Priest John's Busiest Day(2-sat问题)
POJ 3683 Priest John's Busiest Day / OpenJ_Bailian 3788 Priest John's Busiest Day(2-sat问题) Descripti ...
- poj 3686 Priest John's Busiest Day
http://poj.org/problem?id=3683 2-sat 问题判定,输出一组可行解 http://www.cnblogs.com/TheRoadToTheGold/p/8436948. ...
- POJ 3683 Priest John's Busiest Day (2-SAT)
Priest John's Busiest Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6900 Accept ...
- POJ 3683 Priest John's Busiest Day(2-SAT+方案输出)
Priest John's Busiest Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10010 Accep ...
- POJ3683 Priest John's Busiest Day(2-SAT)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11049 Accepted: 3767 Special Judge ...
随机推荐
- MySQL绿色版安装
下载MySQL绿色版 去官方下载mysql.,我下载的是 mysql-5.6.27-winx64,下载后解压缩到D:盘. 安装MySQL服务 拷贝my-default.ini重命名为my.ini,修改 ...
- sql sever基本语法总结
一.数据库导入表 1.先用sql语句创建相应的表,包括表的字段和字段类型 2.导入数据,选择相应的表名,不带'$'符号的表名 二.创建数据库 create datatable 数据库名 三.查看表里的 ...
- iptables snat和dnat
iptables中的snat和dnat是非常有用的,感觉他们二个比较特别,所以单独拿出来说一下. dnat是用来做目的网络地址转换的,就是重写包的目的IP地址.如果一个包被匹配了,那么和它属于同一个流 ...
- javascript函数大全
JavaScript函数大全 1.document.write(""); 输出语句2.JS中的注释为//3.传统的HTML文档顺序是:document->html->( ...
- XAMPP环境访问非Web DocumentRoot下绝对路径
假设你的XAMPP网站文档根目录在C:/xampp/apache/htdocs/下面,那么访问这个目录下的文件是很直接的. 但是有时候需要把用户上传文件指定到特殊目录,比如E盘,那么就需要用户能够访问 ...
- web自动化一(selenium+python+pycharm环境搭建)
年前公司刚刚搭起了web自动化测试框架的环境,趁着过完年还没全部忘掉,准备把如何搭建环境的方法和大家分享下,有哪里不对的地方,请批评指正,共同进步,共勉! 为此我把搭建环境所需的软件打包上传到百度云, ...
- C#实现七牛云存储
云存储,就是把本地的资源文件存放至网络上,可以公网访问.相当于网盘功能,感觉非常方便. 这里介绍的是七牛云存储.有兴趣的可以去官方网站详看 根据官网的介绍,本身是提供SDK的,下载地址,大家可以根据自 ...
- git ssh 配置
创建并切换到 ~/.ssh(存在就直接切换过去) 运行 ssh-keygen 创建 rsa 文件 复制 .pub 的文件内容,添加到网站的公钥列表 Git\etc\ssh\ssh_config 中添加 ...
- js获取对象长度和名称
1.对象的长度不能用.length获取,用js原生的Object.keys可以获取到 var obj = {'name' : 'Tom' , 'sex' : 'male' , 'age' : '14' ...
- java线程间通信1--简单实例
线程通信 一.线程间通信的条件 1.两个以上的线程访问同一块内存 2.线程同步,关键字 synchronized 二.线程间通信主要涉及的方法 wait(); ----> 用于阻塞进程 noti ...