• 原题如下:

    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. 在虚拟机中安装Mysql

    目录 下载Mysql 安装 配置mysql允许远程访问 下载Mysql 下载地址:http://dev.mysql.com/downloads/mysql 我这里下载的是安装版本 安装 配置mysql ...

  2. 收集整理element-ui 表格组件的常用操作方法

    一.简单的表格行内编辑效果 原理是通过Css控制绑定的输入控件与显示值,在选中行样式下对控件进行隐藏或显示. 1.注意下样式的设置 2.change事件 @change="handleEdi ...

  3. 第4篇 Scrum 冲刺博客(专✌️团队)

    一.站立式会议 1.1会议图片 1.2成员完成情况 成员 昨天完成的任务 今天计划完成的任务 工作中的困难 陈忠明 按下载热度返回歌曲信息,与前端尝试交互 歌曲信息的上传/下载包 前后端交互问题 吴茂 ...

  4. Gradle Wrapper

    Gradle Wrapper 当把本地一个项目放入到远程版本库的时候,如果这个项目是以gradle构建的,那么其他人从远程仓库拉取代码之后如果本地没有安装过gradle会无法编译运行,如果对gradl ...

  5. Java BigDecimal使用指南

    提起BigDecimal,相信大家都使用过,之所以总结这篇呢,是因为最近发现项目中使用的不是太规范,在某些场景下甚至出现代码抛出异常的情况, 所以就总结了这篇,希望大家在使用时,可以少踩一些坑. 1. ...

  6. spring4.1及以下跨域配置

    springMVC4.1及以下,就需要对该请求配置filter,,设置请求头可支持跨域 1.web.xml配置 <!-- 跨域问题解决 --> <filter> <fil ...

  7. SEO外包好还是自己组建团队

    http://www.wocaoseo.com/thread-151-1-1.html       营络营销已成为企业不可忽视的一块大肥肉,很多企业都想进来分一杯羹,但是不少企业苦于缺少过硬的技术,无 ...

  8. 《Head First 设计模式》:模板方法模式

    正文 一.定义 模板方法模式在一个方法中定义一个算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以在不改变算法结构的情况下,重新定义算法中的某些步骤. 要点: 模板方法定义了一个算法的步骤,每 ...

  9. spring-boot如何生成元数据与javaBean进行关联用作配置文件提示

    spring-boot如何生成元数据与javaBean进行关联用作配置文件提示 首先需要引入一个jar依赖包,以及一个maven plugin如下所示 <dependency> <g ...

  10. ES5和ES6的继承对比

    ES5的继承实现,这里以最佳实践:寄生组合式继承方式来实现.(为什么是最佳实践,前面有随笔讲过了,可以参考) function Super(name) { this.name = name; } Su ...