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\n");
        else printf("lamentable kingdom\n");
    }
    return 0;
}
时间: 2024-07-29 02:40:16

hdu 1531 King的相关文章

hdu 5640 King&#39;s Cake(模拟)

Problem Description It is the king's birthday before the military parade . The ministers prepared a rectangle cake of size n×m(1≤n,m≤10000) . The king plans to cut the cake himself. But he has a strange habit of cutting cakes. Each time, he will cut

hdu 5641 King&#39;s Phone(暴力模拟题)

Problem Description In a military parade, the King sees lots of new things, including an Andriod Phone. He becomes interested in the pattern lock screen. The pattern interface is a 3×3 square lattice, the three points in the first line are labeled as

hdu 5642 King&#39;s Order

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5642 题意:给出一个n,问一个长度为n的只含有小写字母的序列中,满足其中不含有超过3个连续相同字母的序列的个数有多少. 思路: 设dp[i][j],表示序列第i位为字母j的合法序列的个数.sum[i]表示长度为i的序列有多少个. 假设第i位为字母'a',dp[i][j]就是sum[i-1]*1-不合法的情况. 不合法的情况就是sum[i-4] - dp[i-4][j]. sum[i-4]表示已经计算

HDU 4337 King Arthur&#39;s Knights 找出一条哈密顿回路

n个点m条无向边 输出一条哈密顿回路 #include <cstdio> #include <cstring> #include <iostream> using namespace std; const int N = 155; int n, m; bool mp[N][N]; int S, T, top, Stack[N]; bool vis[N]; void _reverse(int l,int r) { while (l<r) swap(Stack[l++

HDU 5640 King&#39;s Cake

King's Cake Problem Description It is the king's birthday before the military parade . The ministers prepared a rectangle cake of size n×m(1≤n,m≤10000) . The king plans to cut the cake himself. But he has a strange habit of cutting cakes. Each time,

HDU 5643 King&#39;s Game | 约瑟夫环变形

经典约瑟夫环 1 int f[N] ={ 0 }; 2 for(int i=2; i<=n; i++) 3 { 4 f[i] = (f[i-1] + k) % i; 5 } 变形:k是变化的 #include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <stdlib.h> #include <queue> #in

HDU 5642 King&#39;s Order(数位DP)

题目链接:点击打开链接 题意:要求你生成一个合法的字符串, 由小写字母a~z组成, 相同字母相邻出现不能超过3个, 求有多少种组合. 思路:数位DP来做, 用d[i][j][k]表示处理完前i个字母, 第i-1个字母为j,已经连续出现了k次的方法数. 然后每次转移就很简单了, 继续选择字母j(if(k < 3)), 或者换其他的. 细节参见代码: #include<cstdio> #include<cstring> #include<algorithm> #inc

HDU 4337 King Arthur&amp;#39;s Knights 它输出一个哈密顿电路

n积分m文章无向边 它输出一个哈密顿电路 #include <cstdio> #include <cstring> #include <iostream> using namespace std; const int N = 155; int n, m; bool mp[N][N]; int S, T, top, Stack[N]; bool vis[N]; void _reverse(int l,int r) { while (l<r) swap(Stack[l

HDU - 3002 King of Destruction(最小割)

http://acm.hdu.edu.cn/showproblem.php?pid=3002   最小割模板 #include<iostream> #include<cmath> #include<cstring> #include<queue> #include<vector> #include<cstdio> #include<algorithm> #include<map> #include<set