题意:有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. 自定义scrollview右侧的滑动条

    在做这个功能之前我其实是拒绝的,为什么这么说呢,因为我怕麻烦啊!(开玩笑的,怕麻烦就不做程序员了) 很久没有写博客,这次刚好项目中有个有趣的东西,想拿出来分享一下,希望能帮到某些小伙伴. 首先说说需求 ...

  2. SSH连接超时不自动断开

    Putty 启用putty keepalive putty -> Connection -> Seconds between keepalives ( 0 to turn off ),默认 ...

  3. jquery trigger 触发事件小计 -- 关于a标签

    jquery -- trigger触发执行事件方法虽然好用,偶尔也会出些小问题. 在最近得一个项目中需要触发a标签的点击事件时,我就遇到了点小问题.我很想当然的写层这样:$("a" ...

  4. 初探Backbone

    Backbone简介 中文API:http://www.csser.com/tools/backbone/backbone.js.html 英文API:http://backbonejs.org/ B ...

  5. Oracle 11g default profile 默认启用密码过期180天 ORA-28001错误处理

    问题描述:客户反映客户端不能登录应用程序时不能连接.环境:AIX 5.3 + Oracle 11gR2解决:远程Telnet到数据库主机,sqlplus / as sysdba 连接后操作正常,表明数 ...

  6. IOS跳转到设置特定项

    App如何跳转到系统Settings 标签: IOS开发App转到Settings 2015-12-04 15:56 550人阅读 评论(1) 收藏 举报  分类: IOS开发(21)  版权声明:本 ...

  7. Xcode7免证书真机调试

    最近一直忙于项目,对于Xcode7的一些新功能还没去尝试,今天尝试了下挺好用的!避免了以前真机调试繁琐的配置,很是爽啊.又可以节约很多小伙伴的时间了.废话不多说咱们一起来配置一下. 第一步 打开需要真 ...

  8. java的Spring

    歇了一年都没有写过自己博客了,在学习新东西的时候 ,应该把它们记下来,学了.net 去了公司没有多久就转成了java虽然都在做,还是觉得.net好,不过东西还是应该学习下去,这样才是正解! 首先学习的 ...

  9. NPOI 导出Excel2007版本时出现流已关闭问题

    NPOI生产.xlsx文件件时,在使用book.Write(ms);后,会关闭流,这样导致再次使用Respons输出流的时候就出错了. 我看到一些网友提供的解决办法是: public class NP ...

  10. 简单研究Loader笔记

    2015-11-11 18:25:34 1. Loader是什么? /** * Static library support version of the framework's {@link and ...