POJ3683 Priest John's Busiest Day 【2-sat】

题目

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 Si + Di, 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.

输入格式

The first line contains a integer N ( 1 ≤ N ≤ 1000).
The next N lines contain the Si, Ti and Di. Si and Ti are in the format of hh:mm.

输出格式

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.

输入样例

2
08:00 09:00 30
08:15 09:00 20

输出样例

YES
08:00 08:30
08:40 09:00

题解

2-sat + 输出方案
对于每一个婚礼,有两个时间段可以选择,对应两个点
对于每两个婚礼,如果其中两个时间段t1和t1'相交,那么这两个时间段冲突,连边t1->t2',t1'->t2

跑一遍tarjan缩点,若存在婚礼的两个时间段处于同一个强联通分量,则无解

否则输出方案:
QAQ蒟蒻知道有两种方法:
①拓扑排序
将缩完点后的图反向建边,按拓扑顺序访问,每访问到一个没有染色的点,就染为第一种颜色,并令其对应点【对称的那个强两桶分量缩的点】及对应点延伸出去能到达的所有点染另一种颜色【一次dfs】

②按Scc编号
很神奇的方法,所有点对中,输出Scc编号较小的那个即可。。。【比拓扑简单多了 → →】
证明【假的】:tarjan缩点时拓扑序大的先缩,则编号较小,然而我们需要选择拓扑序大的,因为拓扑大的不会推出拓扑序小的

选择一个喜欢方法就可以A了> <

#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define BUG(s,n) for (int i = 1; i <= (n); i++) cout<<s[i]<<' '; puts("");
using namespace std;
const int maxn = 2005,maxm = 2000005,INF = 1000000000;
inline int read(){
    int out = 0,flag = 1; char c = getchar();
    while (c < 48 || c > 57) {if (c == '-') flag = -1; c = getchar();}
    while (c >= 48 && c <= 57) {out = (out << 3) + (out << 1) + c - '0'; c = getchar();}
    return out * flag;
}
int n,m,h[maxn],ne = 1;
struct EDGE{int to,nxt;}ed[maxm];
inline void build(int u,int v){
    ed[ne] = (EDGE){v,h[u]}; h[u] = ne++;
}
int dfn[maxn],low[maxn],Scc[maxn],scci = 0,cnt = 0,st[maxn],top = 0;
void dfs(int u){
    dfn[u] = low[u] = ++cnt;
    st[++top] = u;
    Redge(u)
        if (!dfn[to = ed[k].to])
            dfs(to),low[u] = min(low[u],low[to]);
        else if (!Scc[to]) low[u] = min(low[u],dfn[to]);
    if (dfn[u] == low[u]){
        scci++;
        do{
            Scc[st[top]] = scci;
        }while (st[top--] != u);
    }
}
int B[maxn],T[maxn],ans[maxn],inde[maxn];
void print(int x){
    printf("%02d:%02d ",x / 60,x % 60);
}
bool judge(int u,int v){
    if (T[u] <= B[v] || B[u] >= T[v]) return false;
    return true;
}
int main(){
    n = read(); int a,b,t;
    for (int i = 1; i <= n; i++){
        a = read(); b = read(); B[2 * i - 1] = a * 60 + b;
        a = read(); b = read(); T[2 * i] = a * 60 + b;
        t = read();
        T[2 * i - 1] = B[2 * i - 1] + t;
        B[2 * i] = T[2 * i] - t;
    }
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++){
                if (judge(2 * i,2 * j))
                    build(2 * i,2 * j - 1),build(2 * j,2 * i - 1);
                if (judge(2 * i,2 * j - 1))
                    build(2 * i,2 * j),build(2 * j - 1,2 * i - 1);
                if (judge(2 * i - 1,2 * j))
                    build(2 * i - 1,2 * j - 1),build(2 * j,2 * i);
                if (judge(2 * i - 1,2 * j - 1))
                    build(2 * i - 1,2 * j),build(2 * j - 1,2 * i);
            }
    for (int i = 1; i <= (n << 1); i++) if (!dfn[i]) dfs(i);
    bool flag = true;
    for (int i = 1; i <= n; i++) if (Scc[2 * i] == Scc[2 * i - 1]){
        flag = false; break;
    }
    if (!flag) puts("NO");
    else {
        puts("YES");
        for (int i = 1; i <= n; i++)
            if (Scc[2 * i] < Scc[2 * i - 1])
                print(B[2 * i]),print(T[2 * i]),puts("");
            else print(B[2 * i - 1]),print(T[2 * i - 1]),puts("");
    }
    return 0;
}

转载于:https://www.cnblogs.com/Mychael/p/8283819.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目标检测(Object Detection)是计算机视觉领域的一个核心问题,其主要任务是找出图像中所有感兴趣的目标(物体),并确定它们的类别和位置。以下是对目标检测的详细阐述: 一、基本概念 目标检测的任务是解决“在哪里?是什么?”的问题,即定位出图像中目标的位置并识别出目标的类别。由于各类物体具有不同的外观、形状和姿态,加上成像时光照、遮挡等因素的干扰,目标检测一直是计算机视觉领域最具挑战性的任务之一。 二、核心问题 目标检测涉及以下几个核心问题: 分类问题:判断图像中的目标属于哪个类别。 定位问题:确定目标在图像中的具体位置。 大小问题:目标可能具有不同的大小。 形状问题:目标可能具有不同的形状。 三、算法分类 基于深度学习的目标检测算法主要分为两大类: Two-stage算法:先进行区域生成(Region Proposal),生成有可能包含待检物体的预选框(Region Proposal),再通过卷积神经网络进行样本分类。常见的Two-stage算法包括R-CNN、Fast R-CNN、Faster R-CNN等。 One-stage算法:不用生成区域提议,直接在网络中提取特征来预测物体分类和位置。常见的One-stage算法包括YOLO系列(YOLOv1、YOLOv2、YOLOv3、YOLOv4、YOLOv5等)、SSD和RetinaNet等。 四、算法原理 以YOLO系列为例,YOLO将目标检测视为回归问题,将输入图像一次性划分为多个区域,直接在输出层预测边界框和类别概率。YOLO采用卷积网络来提取特征,使用全连接层来得到预测值。其网络结构通常包含多个卷积层和全连接层,通过卷积层提取图像特征,通过全连接层输出预测结果。 五、应用领域 目标检测技术已经广泛应用于各个领域,为人们的生活带来了极大的便利。以下是一些主要的应用领域: 安全监控:在商场、银行
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值