poj2983--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\n");
else
printf("Reliable\n");
}
}
poj2983--Is the Information Reliable?(差分约束)的更多相关文章
- POJ 2983 Is the Information Reliable? 差分约束
裸差分约束. //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #i ...
- POJ2983 Is the Information Reliable?
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=267#problem/B B - ...
- POJ 2983-Is the Information Reliable?(差分约束系统)
题目地址:POJ 2983 题意:有N个车站.给出一些点的精确信息和模糊信息.精确信息给出两点的位置和距离.模糊信息给出两点的位置.但距离大于等于一.试确定是否全部的信息满足条件. 思路:事实上就是让 ...
- Is the Information Reliable?(差分约束系统)
http://poj.org/problem?id=2983 题意:给出M条信息,判断这些信息的正确性.(1)V A B :表示A,B之间的距离>=1; (2)P A B X :表示A B之间的 ...
- Is the Information Reliable?(差分约束)
Description The galaxy war between the Empire Draco and the Commonwealth of Zibu broke out 3 years a ...
- POJ 2983 Is the Information Reliable? 信息可靠吗 (差分约束,spfa)
题意:有n个站排成一列,针对每个站的位置与距离关系,现有多个约束条件,约束条件分两种:(1)确定的.明确说明站a距离站b多少个单位距离.(2)不确定的.只知道a在b的左边至少1个单位距离. 根据已知 ...
- POJ 2983:Is the Information Reliable?(差分约束)
题目大意:有n个点在一条直线上,有两类关系:P(x,y,v)表示x在y北边v距离处,V(x,y)表示x在y北边至少1距离出,给出一些这样的关系,判断是否有矛盾. 分析: 差分约束模板题,约束条件P:a ...
- POJ 2983 Is the Information Reliable? 依旧差分约束
http://poj.org/problem?id=2983 题目大意: 星际大战开始了.你购买了情报,需要判断它的准确性.已知地方的根据地在由南向北排成一条直线.P A B X,表示A在B北面距离X ...
- 【poj2983】 Is the Information Reliable?
http://poj.org/problem?id=2983 (题目链接) 一个SB错误TLE了半个小时... 题意 一条直线上有n个点,给出m条信息,若为P则表示点A在点B的北方X米,若为V则表示A ...
随机推荐
- [Sgu395][bzoj2363]Binary Cat Club
一道神题…… rzO 发现立杰在初三(http://hi.baidu.com/wjbzbmr/item/4a50c7d8a8114911d78ed0a9据此可以推断)就怒A了此题…… Orz /*** ...
- Meeting Rooms II -- LeetCode
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- [BZOJ 1901] Dynamic Rankings
Link: BZOJ 1901 传送门 Solution: 带修改主席树的模板题 对于静态区间第$k$大直接上主席树就行了 但加上修改后会发现修改时复杂度不满足要求了: 去掉/增加第$i$位上的值时要 ...
- 2017 ACM-ICPC ECFINAL过山车体验
这次采用domjudge判题,算是比较好玩的啦.外榜地址:http://board.acmicpc.cn/ 然后我们很可惜地止步于192名QAQ,没看出C是个傻逼题,没读懂B..我得背锅,亏我还打了那 ...
- poj 1681(Gauss 消元)
Painter's Problem Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5875 Accepted: 2825 ...
- 【Floyd】文化之旅
[NOIP2012]文化之旅 题目描述 有一位使者要游历各国,他每到一个国家,都能学到一种文化,但他不愿意学习任何一 种文化超过一次(即如果他学习了某种文化,则他就不能到达其他有这种文化的国家).不 ...
- ubuntu16安装navicat字体显示不正常,显示方框以及字体倒立
昨天遇到了这个问题,网上找了很多方法都没有真正解决这个问题. 目前其他博客论坛说的主要方法有 1)将安装目录下的./start_navicat中的字符集改为zh_CN.UTF-8 2)将系统的默认字符 ...
- moment.js 日期包装类 (说明示例)
moment.js 日期包装类 Moment.js 1创建时间对象 moment(); ...
- 通配置文件的方式控制java.util.logging.Logger日志输出
转自:http://zochen.iteye.com/blog/616151 简单的实现了下利用JDK中类java.util.logging.Logger来记录日志.主要在于仿照log4j方式用配置文 ...
- IntelliJ IDEA的几种常见的快捷键
在编写代码的时候直接输入psv就会看到一个psvm的提示,此时点击tab键一个main方法就写好了. psvm 也就是public static void main的首字母. 依次还有在方法体内键入f ...