题意:有n对新人要在同一天结婚。结婚时间为Ti到Di,这里有时长为Si的一个仪式需要神父出席。神父可以在Ti-(Ti+Si)这段时间出席也可以在(Di-Si)-Si这段时间。问神父能否出席所有仪式,如果可以输出一组时间安排。

思路:2-SAT。神父可以在开始出席也可以在结束时候出席,要求与其他出席时间没有冲突,这样建图计算即可。另一一定要弄清楚true和false代表的含义。

  1. #include <cstdio>
  2. #include <cmath>
  3. #include <vector>
  4. #include <cstring>
  5. #include <string>
  6. #include <iostream>
  7. using namespace std;
  8. ;
  9. struct TwoSAT
  10. {
  11. int n;
  12. vector<];
  13. ];
  14. ],c;
  15. bool dfs(int x)
  16. {
  17. ]) return false;
  18. if(mark[x]) return true;
  19. mark[x]=true;
  20. S[c++]=x;
  21. ; i<G[x].size(); ++i)
  22. if(!dfs(G[x][i])) return false;
  23. return true;
  24. }
  25. void init(int n)
  26. {
  27. this->n=n;
  28. ; i<n*; ++i) G[i].clear();
  29. memset(mark,,sizeof(mark));
  30. }
  31. void add_clause(int x,int xval,int y,int yval)
  32. {
  33. x=x*+xval;
  34. y=y*+yval;
  35. G[x^].push_back(y);
  36. G[y^].push_back(x);
  37. }
  38. bool solve()
  39. {
  40. ; i<n*; i+=)
  41. {
  42. ])
  43. {
  44. c=;
  45. if(!dfs(i))
  46. {
  47. ) mark[S[--c]]=false;
  48. )) return false;
  49. }
  50. }
  51. }
  52. return true;
  53. }
  54. };
  55. TwoSAT solver;
  56. bool judge(int st1,int ed1,int st2,int ed2)
  57. {
  58. if(st1<=st2&&ed2<=ed1) return true;
  59. if(st2<=st1&&ed1<=ed2) return true;
  60. if(st1<st2&&st2<ed1&&ed2>ed1) return true;
  61. if(st2<st1&&st1<ed2&&ed1>ed2) return true;
  62. return false;
  63. }
  64. int TimetoInt(string str)
  65. {
  66. ]-+(str[]-+(str[]-+(str[]-');
  67. return t;
  68. }
  69. string InttoTime(int t)
  70. {
  71. string str;
  72. ,b=t%;
  73. str+=(a/+');
  74. str+=(a%+');
  75. str+=':';
  76. str+=(b/+');
  77. str+=(b%+');
  78. return str;
  79. }
  80. ],t[][];
  81. int n;
  82. bool solve()
  83. {
  84. solver.init(n);
  85. ; i<n; ++i); a<; ++a)
  86. ; j<n; ++j) ; b<; ++b)
  87. {
  88. int ast,aed;
  89. int bst,bed;
  90. ) ast=t[i][a],aed=t[i][a]+cost[i];
  91. else ast=t[i][a]-cost[i],aed=t[i][a];
  92. )bst=t[j][b],bed=t[j][b]+cost[j];
  93. else bst=t[j][b]-cost[j],bed=t[j][b];
  94. if(judge(ast,aed,bst,bed))
  95. solver.add_clause(i,a^,j,b^);
  96. }
  97. return solver.solve();
  98. }
  99. int main()
  100. {
  101. while(cin>>n)
  102. {
  103. ; i<n; ++i)
  104. {
  105. string st,ed;
  106. cin>>st>>ed>>cost[i];
  107. t[i][]=TimetoInt(st);
  108. t[i][]=TimetoInt(ed);
  109. }
  110. if(!solve()) cout<<"NO"<<endl;
  111. else
  112. {
  113. cout<<"YES"<<endl;
  114. ; i<*n; i+=)
  115. {
  116. if(!solver.mark[i])
  117. cout<<InttoTime(t[i/][])<<][]+cost[i/])<<endl;
  118. else
  119. cout<<InttoTime(t[i/][]-cost[i/])<<][])<<endl;
  120. }
  121. }
  122. }
  123. ;
  124. }

POJ 3683 Priest John's Busiest Day (2-SAT)的更多相关文章

  1. 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. POJ 3683 Priest John's Busiest Day(2-SAT+方案输出)

    Priest John's Busiest Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10010   Accep ...

  3. POJ 3683 Priest John's Busiest Day (2-SAT)

    Priest John's Busiest Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6900   Accept ...

  4. 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 ...

  5. poj - 3683 - Priest John's Busiest Day(2-SAT)

    题意:有N场婚礼,每场婚礼的开始时间为Si,结束时间为Ti,每场婚礼有个仪式,历时Di,这个仪式要么在Si时刻开始,要么在Ti-Di时刻开始,问能否安排每场婚礼举行仪式的时间,使主持人John能参加所 ...

  6. POJ 3683 Priest John's Busiest Day (2-SAT,常规)

    题意: 一些人要在同一天进行婚礼,但是牧师只有1个,每一对夫妻都有一个时间范围[s , e]可供牧师选择,且起码要m分钟才主持完毕,但是要么就在 s 就开始,要么就主持到刚好 e 结束.因为人数太多了 ...

  7. POJ 3683 Priest John's Busiest Day

    2-SAT简单题,判断一下两个开区间是否相交 #include<cstdio> #include<cstring> #include<cmath> #include ...

  8. POJ 3683 Priest John's Busiest Day[2-SAT 构造解]

    题意: $n$对$couple$举行仪式,有两个时间段可以选择,问是否可以不冲突举行完,并求方案 两个时间段选择对应一真一假,对于有时间段冲突冲突的两人按照$2-SAT$的规则连边(把不冲突的时间段连 ...

  9. POJ 3683 Priest John's Busiest Day 【2-Sat】

    这是一道裸的2-Sat,只要考虑矛盾条件的判断就好了. 矛盾判断: 对于婚礼现场 x 和 y,x 的第一段可以和 y 的第一段或者第二段矛盾,同理,x 的第二段可以和 y 的第一段或者第二段矛盾,条件 ...

随机推荐

  1. Cognos10安装注意事项

    cognos10用db2做content management注意事项 1. 建议用UTF-8格式字符2. 建议pagesize用8K或者8K以上3. 新建数据库缓冲池pagesize和以上1.2设置 ...

  2. 20169212《Linux内核原理及分析》第十二周作业

    格式化字符串漏洞实验 格式化字符串漏洞是由像 printf(user_input) 这样的代码引起的,其中 user_input 是用户输入的数据,具有 Set-UID root 权限的这类程序在运行 ...

  3. 我的毕业设计——基于安卓和.NET的笔记本电脑远程控制系统

    手机端: 电脑端:    答辩完成后会开放代码.

  4. Android在代码中使用布局文件中的一个组件

    使用前必须要把组件与其父组件的关系断开,比如有一个组件的名称为scrollChildLayout,则可以使用下面的代码进行分离 ((ViewGroup)scrollChildLayout.getPar ...

  5. 自己不懂的SQL语句用法

    left  join:是SQL语言中的查询类型,即连接查询.它的全称为左外连接,是外连接的一种. 连接通常可以在select语句的from子句或where子句中建立,其语法格式为: select  c ...

  6. ie浏览器兼容问题汇总

    对兼容ie浏览器所遇到的问题及总结 互联快谈 2016-10-28 05:51 1,若直接给一个元素设置absolute定位.在浏览器缩放的时候.位置会错位.解决的方法是给外层的元素设置为relati ...

  7. CSS入门

    CSS,层叠样式表,是对web页面显示效果进行控制的一套标准.当页面的内容受多种样式控制,将会按照一定的顺序处理.CSS的作用:(1)将网页的内容结构和格式控制分开.(2)可以精确控制页面的所有元素. ...

  8. 用java实现简易PC版2048

    import java.awt.Color; import java.awt.EventQueue; import java.awt.BorderLayout; import java.awt.Flo ...

  9. HDU 4941 Magical Forest(2014 Multi-University Training Contest 7)

    思路:将行列离散化,那么就可以用vector 存下10W个点 ,对于交换操作 只需要将行列独立分开标记就行   . r[i] 表示第 i 行存的是 原先的哪行         c[j] 表示 第 j ...

  10. Fibonacci(斐波那契)递归实现。容易看懂

    #include<iostream>using namespace std;int fibonacci(int n){if(n<=0) return 0; else if(n==1) ...