博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj3683(2-SAT 求任意方案)
阅读量:6040 次
发布时间:2019-06-20

本文共 3115 字,大约阅读时间需要 10 分钟。

基础的2-SAT求任意方案的题目。

 

Priest John's Busiest Day
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 7309   Accepted: 2492   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

208:00 09:00 3008:15 09:00 20

Sample Output

YES08:00 08:3008:40 09:00

Source

, Dagger and Facer
 
 
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define INF 0x3fffffff#define N 2020struct node{ int from,to,next;}edge[N*N];int n;int b[N],d[N],k[N];int stk[N],vis[N],low[N],link[N],mark[N];int top,index,id,du[N];//记录入度数int pre[N],cnt,g[N];// g 用来记录排序后的结果int g1[N]; //用来记录缩点后的每一个点所含的点int check(int x,int y,int x1,int y1){ if( y<=x1 || x>=y1 ) return 0; return 1;}void dfs(int s){ mark[s]=1; vis[s]=index++; low[s]=vis[s]; stk[top++]=s; for(int p=pre[s];p!=-1;p=edge[p].next) { int v=edge[p].to; if(mark[v]==0) dfs(v); if(mark[v]==1) low[s]=min(low[s],low[v]); } if(low[s]==vis[s]) { int tmp; id++; do { tmp=stk[top-1]; link[tmp]=id; mark[tmp]=-1; }while(stk[--top]!=s); }}void add_edge(int u,int v){ edge[cnt].from=u; edge[cnt].to=v; edge[cnt].next=pre[u]; pre[u]=cnt++;}void topsort(){ memset(mark,0,sizeof(mark)); top=0; int tcnt=0; for(int i=1;i<=id;i++) if(du[i]==0) { mark[i]=1; stk[top++]=i;//把这个节点入栈 g[tcnt++]=i; } while(top!=0) { int cur=stk[--top]; for(int p=pre[cur];p!=-1;p=edge[p].next) { int v=edge[p].to; if(mark[v]==1) continue; du[v]--; if(du[v]==0) { mark[v]=1; stk[top++]=v; g[tcnt++]=v; } } } //排好了序}void dfs1(int s){ mark[s]=-1; //表示这个点不可以选 for(int p=pre[s];p!=-1;p=edge[p].next) { int v=edge[p].to; dfs1(v); }}int main(){ //freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin); //freopen("C:\\Users\\Administrator\\Desktop\\in.txt","w",stdout); while(~scanf("%d",&n)) { cnt=0; memset(pre,-1,sizeof(pre)); for(int i=0;i

 

 

转载地址:http://ybrhx.baihongyu.com/

你可能感兴趣的文章
Postgres 中 to_char 格式化记录
查看>>
关于联合索引
查看>>
开源 java CMS - FreeCMS2.7 登录移动端管理中心
查看>>
Android FM模块学习之三 FM手动调频
查看>>
Python 设置系统默认编码以及其他编码问题大全
查看>>
Vbs脚本编程简明教程之十四
查看>>
如何UDP/TCP端口是否通了
查看>>
pxe实现系统的自动化安装
查看>>
Redis高可用技术解决方案总结
查看>>
Scale Out Owncloud 高可用(2)
查看>>
何为敏捷
查看>>
HA集群之四:Corosync+Pacemaker+DRBD实现HA Mysql
查看>>
服务器定义
查看>>
我的友情链接
查看>>
MYSQL-实现ORACLE- row_number() over(partition by ) 分组排序功能
查看>>
c# 入门 例子
查看>>
HP Designjet 800PS 日常维护
查看>>
rhel7使用fdisk分区时无法使用全部分区的解决办法
查看>>
Docker 清理命令
查看>>
利用NRPE外部构件监控远程主机
查看>>