• 原题如下:

    Priest John's Busiest Day
    Time Limit: 2000MS   Memory Limit: 65536K
    Total Submissions: 12162   Accepted: 4138   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 SiDi, 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 SiTi and DiSi 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

    YES
    08:00 08:30
    08:40 09:00
  • 题解:定义变量xi用于表示对于结婚仪式i在开始还是结束时进行特别仪式:xi为真↔在开始时进行特别仪式
    这样,对于结婚仪式i和j,如果Si~Si+Di和Sj~Sj+Dj冲突,就有¬xi∨¬xj为真。对于开始和结束、结束和开始、结束和结束三种情况,也可以得到类似的条件。于是,要保证所有特别仪式的时间不冲突,只要考虑将所有的子句用∧连接起来所得到的布尔公式就好了。对于输入样例,可以得到布尔公式(¬x1∨¬x2)∧(x1∨¬x2)∧(x1∨x2),当x1为真而x2为假时,其值为真。这样原问题就转为了2-SAT问题。
    注:判断两个区间[s1, e1]、[s2, e2]是否相交:若max(s1, s2)<min(e1, e2)为真,则两区间相交。
  • 代码:
     #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <stack>
    #include <cstring> using namespace std; const int MAX_N=;
    int N, V;
    int S[MAX_N], T[MAX_N], D[MAX_N];
    vector<int> G[MAX_N*];
    stack<int> s;
    int dfn[MAX_N*], low[MAX_N*];
    int index;
    int cmp[MAX_N*];
    bool instack[MAX_N*];
    int componentnumber; void add_edge(int x, int y)
    {
    G[x].push_back(y);
    } void tarjan(int i)
    {
    dfn[i]=low[i]=index++;
    instack[i]=true;
    s.push(i);
    int j;
    for (int e=; e<G[i].size(); e++)
    {
    j=G[i][e];
    if (dfn[j]==-)
    {
    tarjan(j);
    low[i]=min(low[i], low[j]);
    }
    else
    if (instack[j]) low[i]=min(low[i], dfn[j]);
    }
    if (dfn[i]==low[i])
    {
    componentnumber++;
    do
    {
    j=s.top();
    s.pop();
    instack[j]=false;
    cmp[j]=componentnumber;
    }
    while (j!=i);
    }
    } int main()
    {
    memset(dfn, -, sizeof(dfn));
    scanf("%d", &N);
    for (int i=; i<N; i++)
    {
    int a, b, c, d;
    scanf("%d:%d %d:%d %d", &a, &b, &c, &d, &D[i]);
    S[i]=a*+b;
    T[i]=c*+d;
    }
    V=N*;
    for (int i=; i<N; i++)
    {
    for (int j=; j<i; j++)
    {
    if (min(S[i]+D[i], S[j]+D[j])>max(S[i], S[j]))
    {
    add_edge(i, N+j);
    add_edge(j, N+i);
    }
    if (min(S[i]+D[i], T[j])>max(S[i], T[j]-D[j]))
    {
    add_edge(i, j);
    add_edge(N+j, N+i);
    }
    if (min(T[i], S[j]+D[j])>max(T[i]-D[i], S[j]))
    {
    add_edge(N+i, N+j);
    add_edge(j, i);
    }
    if (min(T[i], T[j])>max(T[i]-D[i], T[j]-D[j]))
    {
    add_edge(N+i, j);
    add_edge(N+j, i);
    }
    }
    }
    for (int i=; i<V; i++)
    {
    if (dfn[i]==-) tarjan(i);
    }
    for (int i=; i<N; i++)
    {
    if (cmp[i]==cmp[N+i])
    {
    printf("NO\n");
    return ;
    }
    }
    printf("YES\n");
    for (int i=; i<N; i++)
    {
    if (cmp[i]<=cmp[N+i])
    {
    printf("%02d:%02d %02d:%02d\n", S[i]/, S[i]%, (S[i]+D[i])/, (S[i]+D[i])%);
    }
    else
    {
    printf("%02d:%02d %02d:%02d\n", (T[i]-D[i])/, (T[i]-D[i])%, T[i]/, T[i]%);
    }
    }
    }

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

  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 3686 Priest John's Busiest Day

    http://poj.org/problem?id=3683 2-sat 问题判定,输出一组可行解 http://www.cnblogs.com/TheRoadToTheGold/p/8436948. ...

  5. 【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 ...

  6. 图论(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 ...

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

  8. POJ3683 Priest John's Busiest Day(2-SAT)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11049   Accepted: 3767   Special Judge ...

  9. HDU 2491 Priest John's Busiest Day(贪心)(2008 Asia Regional Beijing)

    Description John is the only priest in his town. October 26th is the John's busiest day in a year be ...

随机推荐

  1. ASP.NET Core 奇技淫巧之接口代理转发

    前言 先讲讲本文的开发背景吧.. 在如今前后端分离的大背景下,咱的客户又有要求啦~ 要前后端分离~ 然因为种种原因..没办法用用纯前端的框架(其实是学习成本高,又没钱请前端开发人员)... 所以最终决 ...

  2. 不安装证书如何通过模拟器+Fiddler抓包APP的HTTPS请求?

    模拟器抓取https方法 说明:为了解决安卓手线上不能抓取https请求,以下整理通过模拟器抓取https请求方法如下:前置条件:安卓模拟器:夜神抓包工具:Fiddler汉化中文升级版1无需FIDDL ...

  3. 由Thread.join引发的思考

    下面是一段司空见惯的代码,创建两个线程A和线程B,使得线程A优先于线程B执行,使得线程B优先于主线程执行 public class Demo52 { public static void main(S ...

  4. consul、eureka、nacos对比

    consul.eureka.nacos对比 配置中心 eureka 不支持 consul 支持 但用起来偏麻烦,不太符合springBoot框架的命名风格,支持动态刷新 nacos 支持 用起来简单, ...

  5. WordCount( Java )

    Github项目地址:https://github.com/Sabot1203/WordCount 一. 题目描述 实现一个简单而完整的软件工具(源程序特征统计程序). 进行单元测试.回归测试.效能测 ...

  6. Paillier同态加密实现

    一.C++(该方案只实现了加密以及解密) 1.git clone https://github.com/klei0229/paillier.git 2.下载GMP与NTL包: 下载版本以及操作参见ht ...

  7. HTTP基础--网页基础

    网页的组成: 网页可以分为三大部分---HTML,CSS和JavaScript.如果把网页比作一个人的话,HTML相当于骨架,JavaScript相当于肌肉,CSS相当于皮肤,三者结合起来才能形成一个 ...

  8. css基本样式设置

    div中文字居中 如何让一个div中的文字水平和垂直居中?设置如下: 给定该div的长宽(或者二者只给出其一也可) .box{ height: 100px; width: 30%; text-alig ...

  9. DVWA之文件上传(二)

    <?php if( isset( $_POST[ 'Upload' ] ) ) { // Where are we going to be writing to? $target_path = ...

  10. windows server 2008 r2 环境下,实现域名和IP同时都能访问一个网站

    有时候,用域名访问能得到一个页面,用IP地址访问也可以得到一个页面,比如 www.baidu.com 和 61.135.169.125 都可以打开百度页面.一开始要实现这种功能,还真有点不知所措,想了 ...