[caioj]1401: 【约束】差分约束系统2:国王 poj1364

【题意】
给出不超过n的数和m个关系。然后给出ai,bi,接着输入gt或者lt,最后给出di。它们分别表示从ai开始ai+a(i+1)+…+a(i+bi)这些数的和小于(lt)di或大于(gt)di。问是否存在满足m个关系的数列。
【输入格式】
第一行:两个整数n和m,(n<=100),(0《m<=100)。
接下来m行每行输入ai,bi,gt或者lt,di。
多组数据,当n=0时结束。
【输出格式】
若存在这样的数列则输出lamentable kingdom,不存在输出successful conspiracy。
【样例输入】
4 2
1 2 gt 0
2 2 lt 2
1 2
1 0 gt 0
1 0 lt 0
0
【样例输出】
lamentable kingdom
successful conspiracy

也是一个陈题了。。
就随便搞一下。。,推的柿子在程序注释那里
然后这题经过fyc大神不断的实验,发现各种乱七八糟的打法,有时AC,有时WA。。
真是奥妙重重。。
在pojA了,caiojWA了。。
于是发现caioj数据有一点点问题QAQ
于是又来,我A了,fyc依然奥妙重重。。
难道数据还有问题?不管了,反正我A了

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
const int N=50005;
struct qq
{
    int x,y,z,last;
}s[N*10];int num,last[N];
void init (int x,int y,int z)
{
    num++;
    s[num].x=x;s[num].y=y;s[num].z=z;
    s[num].last=last[x];
    last[x]=num;
}
int f[N];
bool in[N];
int du[N];
int n,m;
bool SPFA ()
{
    queue<int> q;
    memset(in,true,sizeof(in));
    memset(f,-63,sizeof(f));
    for (int u=0;u<=n;u++) {du[u]=0;q.push(u);}
    f[0]=0;
    while (!q.empty())
    {
        int x=q.front();q.pop();
        du[x]++;
        if (du[x]>n) return false;
        for (int u=last[x];u!=-1;u=s[u].last)
        {
            int y=s[u].y;
            if (f[y]<f[x]+s[u].z)
            {
                f[y]=f[x]+s[u].z;
                if (in[y]==false)
                {
                    in[y]=true;
                    q.push(y);
                }
            }
        }
        in[x]=false;
    }
    return true;
}

int main()
{
    while (true)
    {

        num=0;memset(last,-1,sizeof(last));
        scanf("%d",&n);
        if (n==0) break;n++;
        scanf("%d",&m);
        for (int u=1;u<=m;u++)
        {
            char ss[5];
            int x,y,z;
            scanf("%d%d%s%d",&x,&y,ss,&z);
            x++;
            if (ss[0]=='g')//s[x+y]-s[x-1]>=z+1----->s[x+y]>=s[x-1]+z+1
                init(x-1,x+y,z+1);
            else//s[x+y]-s[x-1]<=z-1----->s[x-1]>=s[x+y]+1-z
                init(x+y,x-1,1-z);
            n=max(n,x+y);
        }
        if (SPFA()) printf("lamentable kingdom\n");
        else printf("successful conspiracy\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值