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

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

#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
;
struct TwoSAT
{
    int n;
    vector<];
    ];
    ],c;
    bool dfs(int x)
    {
        ]) return false;
        if(mark[x]) return true;
        mark[x]=true;
        S[c++]=x;
        ; i<G[x].size(); ++i)
            if(!dfs(G[x][i])) return false;
        return true;
    }
    void init(int n)
    {
        this->n=n;
        ; i<n*; ++i) G[i].clear();
        memset(mark,,sizeof(mark));
    }
    void add_clause(int x,int xval,int y,int yval)
    {
        x=x*+xval;
        y=y*+yval;
        G[x^].push_back(y);
        G[y^].push_back(x);
    }
    bool solve()
    {
        ; i<n*; i+=)
        {
            ])
            {
                c=;
                if(!dfs(i))
                {
                    ) mark[S[--c]]=false;
                    )) return false;
                }
            }
        }
        return true;
    }
};
TwoSAT solver;
bool judge(int st1,int ed1,int st2,int ed2)
{
    if(st1<=st2&&ed2<=ed1) return true;
    if(st2<=st1&&ed1<=ed2) return true;
    if(st1<st2&&st2<ed1&&ed2>ed1) return true;
    if(st2<st1&&st1<ed2&&ed1>ed2) return true;
    return false;
}
int TimetoInt(string str)
{
    ]-+(str[]-+(str[]-+(str[]-');
    return t;
}
string InttoTime(int t)
{
    string str;
    ,b=t%;
    str+=(a/+');
    str+=(a%+');
    str+=':';
    str+=(b/+');
    str+=(b%+');
    return str;
}
],t[][];
int n;
bool solve()
{
    solver.init(n);
    ; i<n; ++i); a<; ++a)
            ; j<n; ++j) ; b<; ++b)
                {
                    int ast,aed;
                    int bst,bed;
                    ) ast=t[i][a],aed=t[i][a]+cost[i];
                    else ast=t[i][a]-cost[i],aed=t[i][a];
                    )bst=t[j][b],bed=t[j][b]+cost[j];
                    else bst=t[j][b]-cost[j],bed=t[j][b];
                    if(judge(ast,aed,bst,bed))
                        solver.add_clause(i,a^,j,b^);
                }
    return solver.solve();
}
int main()
{
    while(cin>>n)
    {
        ; i<n; ++i)
        {
            string st,ed;
            cin>>st>>ed>>cost[i];
            t[i][]=TimetoInt(st);
            t[i][]=TimetoInt(ed);
        }
        if(!solve()) cout<<"NO"<<endl;
        else
        {
            cout<<"YES"<<endl;
            ; i<*n; i+=)
            {
                if(!solver.mark[i])
                    cout<<InttoTime(t[i/][])<<][]+cost[i/])<<endl;
                else
                    cout<<InttoTime(t[i/][]-cost[i/])<<][])<<endl;
            }
        }
    }
    ;
}

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. openssl 非对称加密 RSA 加密解密以及签名验证签名

    1. 简介 openssl  rsa.h 提供了密码学中公钥加密体系的一些接口, 本文主要讨论利用rsa.h接口开发以下功能 公钥私钥的生成 公钥加密,私钥解密 私钥加密,公钥解密 签名:私钥签名 验 ...

  2. java网络编程,简单的客户端和服务器端

    1.服务器端 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import ...

  3. 基础算法之选择排序Selection Sort

    原理 首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最小(大)元素,然后放到已排序序列的末尾.以此类推,直到所有元素均排序完毕.一种简单直观的排序算 ...

  4. Dedecms有效防止采集的两个实用办法

    现在的采集真是无处不在,尤其是对一些原创性站点,真是烦透了这些采集的人们,如何预防和防止采集呢,站长们!今天先说一下dedecms防采集的办法. 1.随机模版 方法:你多复制N多模版,在body标记附 ...

  5. Spring MVC错误页面配置

    当前SpringMVC非常流行,在大多数情况,我们都需要自定义一些错误页面(例如:401, 402, 403, 500...),以便更友好的提示.对于spring mvc,这些当然是支持自定义的,sp ...

  6. WPF MVVM 学习总结(一)

    ---恢复内容开始--- 1. MVVM简介 在WPF中,MVVM(View-ViewModel-Model)开发模型用的很多,它具有低耦合,可重用行,相对独立的设计和逻辑.所以备受广大开发者的喜爱. ...

  7. H5瀑布流如何实现

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. Could not parse mapping document from input stream

    无法从输入流解析映射文档 1.定义的类名或属性名不对,如:*.hbm.xml文件中属性name对应的实体类name不一致.2.xml头文件中"http://www.hibernate.org ...

  9. Yes, Virginia, Scala is hard

    首先要说的是,我是一个Scala粉丝,我作为一个Scala语言的倡导者差不多有5年历史了.我写了不少Scala语言方面的书和文章.我曾在数十个公司里做过Scala和Lift框架项目的开发.我对很多的S ...

  10. 【编辑器】【Sublime Text】使用笔记

    1.安装 官网下载即可 2.插件 sublime-text - Sublime Text 怎么高亮 Markdown 的文件语法 设置Sublime为VIM模式 如何在sublime 里面设置 ver ...