• poj2983--Is the Information Reliable?(差分约束)


    Is the Information Reliable?
    Time Limit: 3000MS   Memory Limit: 131072K
    Total Submissions: 11125   Accepted: 3492

    Description

    The galaxy war between the Empire Draco and the Commonwealth of Zibu broke out 3 years ago. Draco established a line of defense called Grot. Grot is a straight line with N defense stations. Because of the cooperation of the stations, Zibu’s Marine Glory cannot march any further but stay outside the line.

    A mystery Information Group X benefits form selling information to both sides of the war. Today you the administrator of Zibu’s Intelligence Department got a piece of information about Grot’s defense stations’ arrangement from Information Group X. Your task is to determine whether the information is reliable.

    The information consists of M tips. Each tip is either precise or vague.

    Precise tip is in the form of P A B X, means defense station A is X light-years north of defense station B.

    Vague tip is in the form of V A B, means defense station A is in the north of defense station B, at least 1 light-year, but the precise distance is unknown.

    Input

    There are several test cases in the input. Each test case starts with two integers N (0 < N ≤ 1000) and M (1 ≤ M ≤ 100000).The next M line each describe a tip, either in precise form or vague form.

    Output

    Output one line for each test case in the input. Output “Reliable” if It is possible to arrange N defense stations satisfying all the M tips, otherwise output “Unreliable”.

    Sample Input

    3 4
    P 1 2 1
    P 2 3 1
    V 1 3
    P 1 3 1
    5 5
    V 1 2
    V 2 3
    V 3 4
    V 4 5
    V 3 5

    Sample Output

    Unreliable
    Reliabl

    给出了 P a  b  w 表示 b在a以北w公里, V a  b 表示 b在a北边,最少1公里,问所有 的条件可不能够所有满足。

    由P 能够得到 b - a = w 也就是b - a <= w  &&  a - b <= w ,由 V a  b 得到 b - a >= 1 也就是 a - b <= -1 ;建图,使用最短路,推断是否会有负环。初始dis要所有为0.

     

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    struct node
    {
        int u , v , w ;
    } p[300000];
    int dis[2000] , cnt ;
    void add(int u,int v,int w)
    {
        p[cnt].u = u ;
        p[cnt].v = v ;
        p[cnt++].w = w ;
    }
    int main()
    {
        int i , j , n , m , u , v , w ;
        char str[10] ;
        while(scanf("%d %d", &n, &m)!=EOF)
        {
            cnt = 0 ;
            while(m--)
            {
                scanf("%s", str);
                if(str[0] == 'P')
                {
                    scanf("%d %d %d", &u, &v, &w);
                    add(u,v,-w);
                    add(v,u,w);
                }
                else
                {
                    scanf("%d %d", &u, &v);
                    add(u,v,-1);
                }
            }
            memset(dis,0,sizeof(dis));
            for(i = 1 ; i <= n ; i++)
                for(j = 0 ; j < cnt ; j++)
                    if( dis[ p[j].v ] >dis[ p[j].u ] + p[j].w )
                        dis[ p[j].v ] = dis[ p[j].u ] + p[j].w ;
            for(j = 0 ; j < cnt ; j++)
                if( dis[ p[j].v ] > dis[ p[j].u ] + p[j].w )
                    break;
            if(j < cnt)
                printf("Unreliable
    ");
            else
                printf("Reliable
    ");
        }
    }


     

     

     

  • 相关阅读:
    第二个月课堂009python之总结(002)
    python的接口自动化测试+ddt数据驱动(*****)
    python题(002)
    selenium问题归纳一:多个句柄索引会乱的问题
    多测师讲解python讲解__xlwt__模块(拓展莫模块002)
    多测师python面试题__整理和答案(001)高级讲师肖sir
    第二个月课堂012讲解 _ Unittest框架(上)_高级讲师肖sir
    多测师讲解课堂11课__selenium__错归纳_高级讲师肖sir
    ActionChains定位元素
    css使用方法
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/3996027.html
Copyright © 2020-2023  润新知