zoukankan      html  css  js  c++  java
  • hdu 1531 King

    首先吐槽一下这个题目的题意描述,我看了半天才明白。 下标全部都是乱标的!!!!出题者能不能规范一点下标的写法!!!!

    差分约束系统

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<vector>
    #include<queue>
    #include<algorithm>
    using namespace std;
    
    int n,m,tyu;
    const int maxn=111;
    const int INF=0x7FFFFFFF;
    struct abc
    {
        int startt;
        int endd;
        int costt;
    } node[maxn];
    vector<abc>ljb[maxn];
    int ff[maxn],summ[maxn],dist[maxn];
    
    void spfa()
    {
        queue<int>Q;
        while(!Q.empty()) Q.pop();
        int i;
        for(i=0; i<=n+5; i++) dist[i]=INF;
        memset(ff,0,sizeof(ff));
        memset(summ,0,sizeof(summ));
        dist[0]=0;
        ff[0]=1;
        Q.push(0);
        while(!Q.empty())
        {
            int hh=Q.front();
            Q.pop();
            summ[hh]++;
            if(summ[hh]>n+1)
            {
                tyu=1;
                break;
            }
            ff[hh]=0;
            for(i=0; i<ljb[hh].size(); i++)
            {
                abc noww;
                noww=ljb[hh][i];
                if(dist[hh]+noww.costt<dist[noww.endd])
                {
                    dist[noww.endd]=dist[hh]+noww.costt;
                    if(ff[noww.endd]==0)
                    {
                        ff[noww.endd]=1;
                        Q.push(noww.endd);
                    }
                }
            }
        }
    }
    int main()
    {
        int i,si,ni,ki,tott;
        char oi[5];
        while(~scanf("%d",&n))
        {
            if(n==0) break;
            scanf("%d",&m);
            tott=0;
            for(i=0; i<=n+5; i++) ljb[i].clear();
            for(i=0; i<m; i++)
            {
                scanf("%d%d%s%d",&si,&ni,oi,&ki);
                if(strcmp("lt",oi)==0)
                {
                    node[tott].startt=si;
                    node[tott].endd=si+ni+1;
                    node[tott].costt=ki-1;
                    ljb[si].push_back(node[tott]);
                    tott++;
                }
                else if(strcmp("gt",oi)==0)
                {
                    node[tott].startt=si+ni+1;
                    node[tott].endd=si;
                    node[tott].costt=-(ki+1);
                    ljb[si+ni+1].push_back(node[tott]);
                    tott++;
                }
            }
            for(i=1; i<=n+1; i++)
            {
                node[tott].startt=0;
                node[tott].endd=i;
                node[tott].costt=0;
                ljb[0].push_back(node[tott]);
                tott++;
            }
            tyu=0;
            spfa();
            if(tyu==1) printf("successful conspiracy
    ");
            else printf("lamentable kingdom
    ");
        }
        return 0;
    }
  • 相关阅读:
    MSIL实用指南-一维数组的操作
    MSIL实用指南-给字段、属性、方法、类、程序集加Attribute
    MSIL实用指南-比较运算
    MSIL实用指南-逻辑运算
    MSIL实用指南-位运算
    MSIL实用指南-数学运算
    MSIL实用指南-创建对象
    MSIL实用指南-装箱拆箱
    MSIL实用指南-生成构造函数
    K8S从入门到放弃系列-(5)kubernetes集群之kube-apiserver部署
  • 原文地址:https://www.cnblogs.com/zufezzt/p/4567684.html
Copyright © 2011-2022 走看看