poj 3683 Priest John's Busiest Day(2-SAT)

本文介绍了一个关于神父如何合理安排日程以参加多场婚礼中特殊仪式的问题。通过2-SAT算法解决冲突时间安排,确保每场婚礼都能顺利完成。

Language:
Priest John's Busiest Day
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 8547 Accepted: 2918 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 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.

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


n对新人举办婚礼 需要神父主持 有一个特殊的仪式 必须需要神父在场

给出婚礼开始和结束的时间 以及特殊仪式所需要的时间 另外这个特殊仪式必须在开始或者结束时进行

神父不能同时参加多个仪式 问有木有一种时间安排可以使得神父能够参加全部的仪式


2-SAT解法

a或b转化为 非a=>b且非b=>a

xi为真<=>在开始时进行特别仪式

记#xi为xi的反 

如果Si~Si+Di和Sj~Sj+Dj冲突 则有#xi或#xj为真(xi且xj为假)

类似于这样的还有

Si~Si+Di和Tj-Dj~Tj  Ti-Di~Ti和Sj~Sj+Dj   Ti-Di~Ti和Tj-Dj~Tj

建图 利用连通分量 求出是否有可行解  利用拓扑序 求出任意一种解

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <queue>

#define MEM(a,x) memset(a,x,sizeof a)
#define eps 1e-8
#define MOD 10009
#define MAXN 5010
#define MAXM 2000100
#define INF 99999999
#define ll __int64
#define bug cout<<"here"<<endl
#define fread freopen("ceshi.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)

using namespace std;

int Read()
{
    char ch;
    int a = 0;
    while((ch = getchar()) == ' ' | ch == '\n');
    a += ch - '0';
    while((ch = getchar()) != ' ' && ch != '\n')
    {
        a *= 10;
        a += ch - '0';
    }
    return a;
}

void Print(int a)
{
     if(a>9)
         Print(a/10);
     putchar(a%10+'0');
}
struct Edge
{
    int to,next;
}edge[MAXM];
int head[MAXN],tot;
int low[MAXN],dfn[MAXN],stack[MAXN],belong[MAXN];
int index,top;
bool instack[MAXN];
int scc;
void addedge(int u,int v)
{
    edge[tot].to=v; edge[tot].next=head[u]; head[u]=tot++;
}
void Tarjan(int u)
{
    int v;
    low[u]=dfn[u]=++index;
    stack[top++]=u;
    instack[u]=1;
    for(int i=head[u];i!=-1;i=edge[i].next)
    {
        v=edge[i].to;
        if(!dfn[v])
        {
            Tarjan(v);
            if(low[u]>low[v]) low[u]=low[v];
        }
        else if(instack[v]&&low[u]>dfn[v])
            low[u]=dfn[v];
    }
    if(low[u]==dfn[u])
    {
        scc++;
        do
        {
            v=stack[--top];
            instack[v]=0;
            belong[v]=scc;
        }while(u!=v);
    }
}

int solvable(int N)
{
    MEM(dfn,0); MEM(instack,0);
    index=scc=top=0;
    for(int i=1;i<=2*N;i++)
        if(!dfn[i])
            Tarjan(i);
    for(int i=1;i<=N;i++)
    {
        if(belong[i]==belong[N+i])
        {
            return 0;
        }
    }
    return 1;
}
void init()
{
    tot=0;
    MEM(head,-1);
}

int s[MAXN],t[MAXN],d[MAXN];
queue<int> q1,q2;
vector<vector<int> > dag;
char color[MAXN];
int indeg[MAXN];
int cf[MAXN];
void solve(int n)
{
    dag.assign(scc+1,vector<int>());
    MEM(indeg,0); MEM(color,0);
    for(int u=1;u<=2*n;u++)
    {
        for(int i=head[u];i!=-1;i=edge[i].next)
        {
            int v=edge[i].to;
            if(belong[u]!=belong[v])
            {
                dag[belong[v]].push_back(belong[u]);
                indeg[belong[u]]++;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        cf[belong[i]]=belong[i+n];
        cf[belong[i+n]]=belong[i];
    }
    while(!q1.empty()) q1.pop();
    while(!q2.empty()) q2.pop();
    for(int i=1;i<=scc;i++)
        if(indeg[i]==0)
            q1.push(i);
    while(!q1.empty())
    {
        int u=q1.front();
        q1.pop();
        if(color[u]==0)
        {
            color[u]='R';
            color[cf[u]]='B';
        }
        int sz=dag[u].size();
        for(int i=0;i<sz;i++)
        {
            indeg[dag[u][i]]--;
            if(indeg[dag[u][i]]==0)
                q1.push(dag[u][i]);
        }
    }
}


int main()
{
//    fread;
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int s1,s2,t1,t2;
        for(int i=1;i<=n;i++)
        {
            scanf("%d:%d%d:%d%d",&s1,&s2,&t1,&t2,&d[i]);
            s[i]=s1*60+s2;
            t[i]=t1*60+t2;
        }
        init();
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<i;j++)
            {
                if(min(s[i]+d[i],s[j]+d[j])>max(s[i],s[j]))
                {
                    addedge(i,n+j);
                    addedge(j,n+i);
                }
                if(min(s[i]+d[i],t[j])>max(s[i],t[j]-d[j]))
                {
                    addedge(i,j);
                    addedge(n+j,n+i);
                }
                if(min(t[i],s[j]+d[j])>max(t[i]-d[i],s[j]))
                {
                    addedge(n+i,n+j);
                    addedge(j,i);
                }
                if(min(t[i],t[j])>max(t[i]-d[i],t[j]-d[j]))
                {
                    addedge(n+i,j);
                    addedge(n+j,i);
                }
            }
        }
        int flag=solvable(n);

        if(!flag)
        {
            puts("NO");
            continue;
        }
        puts("YES");
        solve(n);
        for(int i=1;i<=n;i++)
        {
            if(color[belong[i]]=='R')
            {
                printf("%02d:%02d %02d:%02d\n",s[i]/60,s[i]%60,(s[i]+d[i])/60,(s[i]+d[i])%60);
            }
            else
            {
                printf("%02d:%02d %02d:%02d\n",(t[i]-d[i])/60,(t[i]-d[i])%60,t[i]/60,t[i]%60);
            }
        }
    }
    return 0;
}





内容概要:本文围绕可变桨叶四旋翼无人机的规范控制与点对点运动模拟展开,重点研究优化推力分配策略在翻转动作中的应用与性能比较。通过Matlab代码实现,构建了四旋翼动力学模型,并设计了多种控制算法以实现精确的姿态调整与轨迹跟踪。研究对比了不同推力分配方案在执行高机动性翻转动作时的稳定性、能耗效率与响应速度,旨在提升无人机在复杂飞行任务中的动态性能与控制精度。该仿真研究为无人机飞控系统的设计与优化提供了理论依据和技术支持。; 适合人群:具备一定自动控制理论基础和Matlab编程能力,从事无人机控制、飞行器动力学或机器人系统研究的科研人员及研究生。; 使用场景及目标:① 实现四旋翼无人机在三维空间中的精确点对点运动控制;② 对比分析不同推力分配策略在执行翻转等高难度动作时的控制效果与能耗表现,优化飞行性能;③ 为无人机自主飞行、特技飞行及复杂环境下的机动控制提供算法验证平台。; 阅读建议:此资源以Matlab仿真为核心,建议读者结合相关控制理论知识,深入理解代码实现细节,重点关注动力学建模、控制律设计与推力分配模块。在学习过程中,应动手调试参数,复现文中翻转动作的仿真结果,并尝试拓展至其他复杂飞行任务,以加深对无人机控制机理的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值