poj 3683 Priest John's Busiest Day(2-SAT 输出路径)

Priest John's Busiest Day
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 7177 Accepted: 2450 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 yearN couples plan to get married on the blessed day. The i-th couple plan to hold their wedding from timeSi 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. Thei-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 fromSi to Si + Di, or fromTi - 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 Si, Ti andDi. Si and Ti are in the format ofhh: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 anotherN 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个婚礼,牧师要给每个婚礼做一个仪式,每个仪式都需要耗费相应的时间。现在给出每个婚礼的开始时间s、结束时间e和仪式的持续时间d,仪式只能在时间段  (s,s+d)或(e-d,e)内进行,牧师在同一时间内只能给一个婚礼做仪式。问牧师能否给所有婚礼都做仪式。若能,则输出每个婚礼仪式的开始时间或持续时间。
思路:每个婚礼有两个仪式时间段供选择,容易想到是2-SAT问题。把每个婚礼i拆成两个点2*i和2*i+1分别代表上述的两个仪式时间段,然后分别和其他婚礼的两个仪式时间段比较,若相冲突,则可以构图了。构图完成后,用tarjan判断是否有解。若有解,则对于缩点后的新图,建立一个反图。在反图上进行拓扑排序,确定要输出的仪式时间。
 
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <map>
#include <cstdlib>
#define L(rt) (rt<<1)
#define R(rt) (rt<<1|1)
#define ll long long
using namespace std;

const int maxn=2005;
const int INF=1000000000;
struct node
{
    int v,next;
}edge[maxn*maxn];
int G[maxn],NG[maxn],scc[maxn],stack[maxn];
int low[maxn],dfn[maxn],in[maxn],s[maxn][2],e[maxn][2];
bool ins[maxn],flag[maxn];
int n,m,num,cnt,top,snum;
void init()
{
    memset(G,-1,sizeof(G));
    memset(NG,-1,sizeof(NG));
    num=0;
}
void add(int *head,int u,int v)
{
    edge[num].v=v;
    edge[num].next=head[u];
    head[u]=num++;
}
bool ok(int x1,int y1,int x2,int y2)
{
    if(y1<=x2||y2<=x1) return false;
    return true;
}
void input()
{
   int h1,h2,m1,m2,d;
   for(int i=0;i<n;i++)
   {
       scanf("%d:%d%d:%d%d",&h1,&m1,&h2,&m2,&d);
       s[i][0]=h1*60+m1;
       s[i][1]=s[i][0]+d;
       e[i][1]=h2*60+m2;
       e[i][0]=e[i][1]-d;
   }
   for(int i=0;i<n;i++)
   for(int j=i+1;j<n;j++)
   {
       if(ok(s[i][0],s[i][1],s[j][0],s[j][1]))
       {
           add(G,2*i,2*j+1);
           add(G,2*j,2*i+1);
       }
       if(ok(s[i][0],s[i][1],e[j][0],e[j][1]))
       {
           add(G,2*i,2*j);
           add(G,2*j+1,2*i+1);
       }
       if(ok(e[i][0],e[i][1],s[j][0],s[j][1]))
       {
           add(G,2*i+1,2*j+1);
           add(G,2*j,2*i);
       }
       if(ok(e[i][0],e[i][1],e[j][0],e[j][1]))
       {
           add(G,2*i+1,2*j);
           add(G,2*j+1,2*i);
       }
   }
}
void dfs(int u)
{
    int x;
    dfn[u]=low[u]=++cnt;
    stack[top++]=u;
    ins[u]=true;
    for(int i=G[u];i!=-1;i=edge[i].next)
    {
        int v=edge[i].v;
        if(!dfn[v])
        {
            dfs(v);
            low[u]=min(low[u],low[v]);
        }
        else if(ins[v]) low[u]=min(low[u],dfn[v]);
    }
    if(low[u]==dfn[u])
    {
        do{
            x=stack[--top];
            ins[x]=false;
            scc[x]=snum;
        }while(x!=u);
        snum++;
    }
}
void tarjan()
{
    memset(dfn,0,sizeof(dfn));
    memset(ins,false,sizeof(ins));
    cnt=top=snum=0;
    for(int i=0;i<2*n;i++)
    if(!dfn[i]) dfs(i);
}
void toposort()
{
    int x;
    queue<int>Q;
    memset(flag,false,sizeof(flag));
    for(int i=0;i<snum;i++)
    if(!in[i]) Q.push(i);
    while(!Q.empty())
    {
        x=Q.front();
        Q.pop();
        for(int i=0;i<2*n;i++)
        if(scc[i]==x&&!flag[i^1])
        flag[i]=true;
        for(int i=NG[x];i!=-1;i=edge[i].next)
        {
            int v=edge[i].v;
            in[v]--;
            if(!in[v]) Q.push(v);
        }
    }
    for(int i=0;i<2*n;i++)
    if(flag[i])
    {
        if(i&1) printf("%02d:%02d %02d:%02d\n",e[i/2][0]/60,e[i/2][0]%60,e[i/2][1]/60,e[i/2][1]%60);
        else printf("%02d:%02d %02d:%02d\n",s[i/2][0]/60,s[i/2][0]%60,s[i/2][1]/60,s[i/2][1]%60);
    }
}
void solve()
{
    for(int i=0;i<2*n;i+=2)
    if(scc[i]==scc[i^1])
    {
        printf("NO\n");
        return;
    }
    memset(in,0,sizeof(in));
    for(int u=0;u<2*n;u++)
    for(int i=G[u];i!=-1;i=edge[i].next)
    {
        int v=edge[i].v;
        if(scc[u]!=scc[v])
        {
            add(NG,scc[v],scc[u]);
            in[scc[u]]++;
        }
    }
    printf("YES\n");
    toposort();
}
int main()
{
    while(~scanf("%d",&n))
    {
        init();
        input();
        tarjan();
        solve();
    }
    return 0;
}


内容概要:本文详细探讨了双馈风力发电机(DFIG)在Simulink环境下的建模方法及其在不同风速条件下的电流与电压波形特征。首先介绍了DFIG的基本原理,即定子直接接入电网,转子通过双向变流器连接电网的特点。接着阐述了Simulink模型的具体搭建步骤,包括风力机模型、传动系统模型、DFIG本体模型和变流器模型的建立。文中强调了变流器控制算法的重要性,特别是在应对风速变化时,通过实时调整转子侧的电压和电流,确保电流和电压波形的良好特性。此外,文章还讨论了模型中的关键技术和挑战,如转子电流环控制策略、低电压穿越性能、直流母线电压脉动等问题,并提供了具体的决方案和技术细节。最终,通过对故障工况的仿真测试,验证了所建模型的有效性和优越性。 适用人群:从事风力发电研究的技术人员、高校相关专业师生、对电力电子控制系统感兴趣的工程技术人员。 使用场景及目标:适用于希望深入了DFIG工作原理、掌握Simulink建模技能的研究人员;旨在帮助读者理DFIG在不同风速条件下的动态响应机制,为优化风力发电系统的控制策略提供理论依据和技术支持。 其他说明:文章不仅提供了详细的理论释,还附有大量Matlab/Simulink代码片段,便于读者进行实践操作。同时,针对一些常见问题给出了实用的调试技巧,有助于提高仿真的准确性和可靠性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值