POJ 3683 神父赶婚宴 2-SAT+输出模板
题意:一个小镇里面只有一个牧师,现在有些新人要结婚,需要牧师分别去主持一个仪式,给出每对新人婚礼的开始时间 s 和结束时间 t ,还有他们俩的这个仪式需要的时间(每对新人需要的时间长短可能不同) d ,牧师可以在婚礼开始的时间 d 内(s 到 s+d)或者是结束前的时间 d 内(t - d 到 t)完成这个仪式。现在问能否给出一种安排,让牧师能完成所有夫妇婚礼的仪式,如果可以,输出一种安排。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
#define MM(a,b) memset(a,b,sizeof(a));
const double eps = 1e-10;
const int inf =0x7f7f7f7f;
const double pi=acos(-1);
const int maxn=100+1000; int n,m,pre[2*maxn],lowlink[2*maxn],dfs_clock,sccno[2*maxn],scc_cnt;
int opp[2*maxn],st[2*maxn],ed[2*maxn],tt[2*maxn],indeg[2*maxn],color[2*maxn]; struct node{
int l,r;
}ne[2*maxn];
vector<int> G[2*maxn],g[2*maxn];
stack<int> S; void tarjan(int u)
{
pre[u]=lowlink[u]=++dfs_clock;
S.push(u);
for(int i=0;i<G[u].size();i++)
{
int v=G[u][i];
if(!pre[v])
{
tarjan(v);
lowlink[u]=min(lowlink[u],lowlink[v]);
}
else if(!sccno[v])
lowlink[u]=min(lowlink[u],pre[v]);
} if(pre[u]==lowlink[u])
{
scc_cnt++;
for(;;)
{
int cur=S.top();S.pop();
sccno[cur]=scc_cnt;
if(u==cur) break;
}
}
} bool find_scc()
{
MM(pre,0);
MM(sccno,0);
MM(lowlink,0);
dfs_clock=scc_cnt=0; for(int i=0;i<2*n;i++)
if(!pre[i])
tarjan(i); for(int i=0;i<2*n;i++)
if(sccno[i]==sccno[i^1])
return false;
return true;
} bool inter(node a,node b)
{
return a.r>b.l&&a.l<b.r;
} void build()
{
for(int i=0;i<2*n;i++)
G[i].clear(); for(int i=0;i<2*n;i++)
for(int j=i+1;j<2*n;j++)//对任意两个点都进行下判断
if(inter(ne[i],ne[j]))
{
G[i].push_back(j^1);
G[j].push_back(i^1);
}
} void topsort()
{
MM(indeg,0);
MM(color,0);
for(int i=1;i<=scc_cnt;i++)
g[i].clear(); for(int i=0;i<2*n;i++)
{
opp[sccno[i]]=sccno[i^1];
opp[sccno[i^1]]=sccno[i];
} for(int u=0;u<2*n;u++)
for(int i=0;i<G[u].size();i++)
{
int a=sccno[u],b=sccno[G[u][i]];
if(a!=b)
{
indeg[a]++;
g[b].push_back(a);
}
} queue<int> q;
for(int i=1;i<=scc_cnt;i++)
if(!indeg[i]) q.push(i); while(q.size())
{
int u=q.front();q.pop();
if(!color[u])
{
color[u]=1;
color[opp[u]]=-1;
}
for(int i=0;i<g[u].size();i++)
{
int v=g[u][i];
indeg[v]--;
if(!indeg[v]) q.push(v);
}
} for(int i=0;i<n;i++)
if(color[sccno[i<<1]]==1)
printf("%02d:%02d %02d:%02d\n",ne[i<<1].l/60,ne[i<<1].l%60,ne[i<<1].r/60,ne[i<<1].r%60);
else
printf("%02d:%02d %02d:%02d\n",ne[i<<1^1].l/60,ne[i<<1^1].l%60,ne[i<<1^1].r/60,ne[i<<1^1].r%60);
} int main()
{
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
{
int a,b,c,d,e; scanf("%d:%d %d:%d %d",&a,&b,&c,&d,&e);
ne[i<<1].l=a*60+b;
ne[i<<1].r=a*60+b+e;
ne[i<<1^1].l=60*c+d-e;
ne[i<<1^1].r=60*c+d;
}//针对每个点,其反点是^关系 build(); if(find_scc())
{
printf("YES\n");
topsort();
}
else printf("NO\n");
}
return 0;
}
POJ 3683 神父赶婚宴 2-SAT+输出模板的更多相关文章
- poj 3683 2-sat建图+拓扑排序输出结果
发现建图的方法各有不同,前面一题连边和这一题连边建图的点就不同,感觉这题的建图方案更好. 题意:给出每个婚礼的2个主持时间,每个婚礼的可能能会冲突,输出方案. 思路:n个婚礼,2*n个点,每组点是对称 ...
- POJ 3683 Priest John's Busiest Day(2-SAT+方案输出)
Priest John's Busiest Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10010 Accep ...
- POJ 3683 Priest John's Busiest Day (2-SAT+输出可行解)
题目地址:POJ 3683 第一次做须要输出可行解的题目. . .大体思路是先用强连通来推断是否有可行解,然后用逆序建图.用拓扑排序来进行染色.然后输出可行解. 详细思路见传送门 由于推断的时候少写了 ...
- 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 ...
- 2-SAT的小总结(POJ 3683 POJ 3207)
记住几个最重要的公式: xANDy=0<=>(x=>y′)AND(y=>x′) xANDy=1<=>(x′=>x)AND(y′=>y) xORy=0&l ...
- poj 3683(2-sat+输出一组可行解)
题目链接:http://poj.org/problem?id=3683 思路:对于每个结婚仪式,只有在开始或结束时进行这两种选择,我们可以定义xi为真当且仅当在开始时进行.于是我们可以通过时间先后确定 ...
- POJ 3683 Priest John's Busiest Day(2-SAT 并输出解)
Description John is the only priest in his town. September 1st is the John's busiest day in a year b ...
- poj 3683 2-sat问题,输出任意一组可行解
/* 2sat问题 输出任意一组可行解 */ #include<stdio.h> #include<string.h> #include<stdlib.h> #in ...
- poj 3683(2-SAT+SCC)
传送门:Problem 3683 https://www.cnblogs.com/violet-acmer/p/9769406.html 参考资料: [1]:挑战程序设计竞赛 题意: 有n场婚礼,每场 ...
随机推荐
- GS7 安装使用Oracle19c 客户端的说明
1. 最近Oracle放出了 windows版本的oracle19c的安装文件(具体时间不详, 自己知道的时候比较晚了) 2. 发现文件其实比较多如图示: 3. 经过自己测试实现发现 不能使用 如下 ...
- redis缓存穿透00
缓存穿透 缓存穿透,是指查询一个数据库一定不存在的数据.正常的使用缓存流程大致是,数据查询先进行缓存查询,如果key不存在或者key已经过期,再对数据库进行查询,并把查询到的对象,放进缓存.如果数据库 ...
- 基于 Vue.js 2.0 酷炫自适应背景视频登录页面的设计『转』
本文讲述如何实现拥有酷炫背景视频的登录页面,浏览器窗口随意拉伸,背景视频及前景登录组件均能完美适配,背景视频可始终铺满窗口,前景组件始终居中,视频的内容始终得到最大限度的保留,可以得到最好的视觉效果. ...
- php7.2.1 安装
yum -y install wget openssl* gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype ...
- Docker 构建私有镜像仓库
在使用Docker一段时间后,往往会发现手头积累了大量的自定义镜像文件,这些文件通过公有仓库进行管理并不方便,另外有时候只是希望在内部用户之间进行分享,不希望暴露出去.这种情况下,就有必要搭建一个本地 ...
- linux安装git服务器和svn服务器
linux版本 linux版本为CentOS 6.8 (要注意有些软件的安装方法在各个linux版本之间也是存在差异的) git服务器 git服务器需要提供一个UI供开发人员创建项目管理项目,选择使用 ...
- [Next] 六.next的优化
导出 html 并开启服务 我们将 pages 下页面导出为静态 HTML 页面.首先,next.config.js 在应用程序的根目录中创建一个名为的文件,并添加以下内容 exportPathMap ...
- leetcode 1282. Group the People Given the Group Size They Belong To
There are n people whose IDs go from 0 to n - 1 and each person belongs exactly to one group. Given ...
- mybatis-generator遇到到的问题
1.Unknown system variable 'query_cache_size' https://blog.csdn.net/qq_21870555/article/details/80711 ...
- 多线程学习-- part 1 Thread
一.Thread的使用 (1)sleep:进程等一会 (2)join:让并发处理变成串行 (3)start:启动线程的唯一方法,start()首先为线程分配必须的系统资源,调度线程运行并执行线程的ru ...