题目大意:有n个点在一条直线上,有两类关系:P(x,y,v)表示x在y北边v距离处,V(x,y)表示x在y北边至少1距离出,给出一些这样的关系,判断是否有矛盾。

分析:

差分约束模板题,约束条件P:a-b>=v a-b<=v即a-b>=v b-a<=-v,V:a-b>=1即b-a<=-1,构图spfa判负权回路即可。

需要注意 的是存图时不能用一个二维数组存边权,因为两点间会有多条边。、

spfa判断负权回路的方法,记录每个点进队次数,超过点的数目即存在负权回路。

代码:

program infor;
type
point=^node;
node=record
x,len:longint; next:point;
end;
var
a:array[..]of point;
q:array[..]of longint;
dis,vis:array[..]of longint;
g:array[..]of boolean;
n,i,m,x,y,v:longint; c:char; p:point;
procedure put(x,y,v:longint);
var p:point;
begin
new(p);
p^.x:=x; p^.len:=v; p^.next:=a[y];a[y]:=p;
end;
procedure getnew;
var i:longint;
begin
fillchar(q,sizeof(q),);
fillchar(g,sizeof(g),false); fillchar(vis,sizeof(vis),);
for i:= to n do dis[i]:=maxlongint div ;
for i:= to n do begin dispose(a[i]); new(a[i]); a[i]:=nil; end;
dis[]:=; g[]:=true; q[]:=;
end;
function spfa:boolean;
var x,y,h,t:longint; p:point;
begin
h:=; t:=;
while h<t do
begin
inc(h); x:=q[h]; g[x]:=false; new(p);p:=a[x];
while p<>nil do
begin
y:=p^.x;
if dis[x]+p^.len<dis[y] then
begin
dis[y]:=dis[x]+p^.len;
if g[y]=false then
begin
inc(t); q[t]:=y; g[y]:=true;
end;
inc(vis[y]); if vis[y]>n then exit(false);
end;
p:=p^.next;
end;
end;
exit(true);
end;
begin
readln(n,m);
while (n<>)or(m<>) do
begin
getnew;
for i:= to n do put(i,,);
for i:= to m do
begin
read(c);
if c='P' then
begin read(x,y,v); put(x,y,v); put(y,x,-v); end
else if c='V' then begin read(x,y); put(y,x,-); end;
if i<m then readln;
end;
if spfa then writeln('Reliable') else writeln('Unreliable');
n:=; m:=;
readln(n,m);
end;
end.

POJ 2983:Is the Information Reliable?(差分约束)的更多相关文章

  1. POJ 2983 Is the Information Reliable? 差分约束

    裸差分约束. //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #i ...

  2. POJ 2983 Is the Information Reliable? 依旧差分约束

    http://poj.org/problem?id=2983 题目大意: 星际大战开始了.你购买了情报,需要判断它的准确性.已知地方的根据地在由南向北排成一条直线.P A B X,表示A在B北面距离X ...

  3. POJ 2983 Is the Information Reliable? 信息可靠吗 (差分约束,spfa)

    题意:有n个站排成一列,针对每个站的位置与距离关系,现有多个约束条件,约束条件分两种:(1)确定的.明确说明站a距离站b多少个单位距离.(2)不确定的.只知道a在b的左边至少1个单位距离.  根据已知 ...

  4. POJ 2983 Is the Information Reliable?(差分约束系统)

    http://poj.org/problem?id=2983 题意:N 个 defense stations,M条消息,消息有精确和模糊之分,若前边为P.则为精确消息,有两个defense stati ...

  5. ●POJ 2983 Is the Information Reliable?

    题链: http://poj.org/problem?id=2983 题解: 差分约束. 1).对于条件(P u v w),不难发现反映到图上就是: $dis[u]-dis[v]=w$,所以添加两条边 ...

  6. POJ 2983-Is the Information Reliable?(差分约束系统)

    题目地址:POJ 2983 题意:有N个车站.给出一些点的精确信息和模糊信息.精确信息给出两点的位置和距离.模糊信息给出两点的位置.但距离大于等于一.试确定是否全部的信息满足条件. 思路:事实上就是让 ...

  7. POJ 3159 Candies 解题报告(差分约束 Dijkstra+优先队列 SPFA+栈)

    原题地址:http://poj.org/problem?id=3159 题意大概是班长发糖果,班里面有不良风气,A希望B的糖果不比自己多C个.班长要满足小朋友的需求,而且要让自己的糖果比snoopy的 ...

  8. POJ 之 Is the Information Reliable?

    B - Is the Information Reliable? Time Limit:3000MS     Memory Limit:131072KB     64bit IO Format:%I6 ...

  9. 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之间的 ...

  10. POJ 3159 Candies(spfa、差分约束)

    Description During the kindergarten days, flymouse was the monitor of his class. Occasionally the he ...

随机推荐

  1. POJ 3666 Making the Grade(区间dp)

    修改序列变成非递减序列,使得目标函数最小.(这题数据有问题,只要求非递减 从左往右考虑,当前a[i]≥前一个数的取值,当固定前一个数的取值的时候我们希望前面操作的花费尽量小. 所以状态可以定义为dp[ ...

  2. Linux 的歷史

    Unix 狹義作業系統提供應用程式及命令直譯器. 作業系統發展初期並不具可攜性. Bell, GE 及 MIT 合作開發的 "Multice" 系統( 相容分時系統 ). 1969 ...

  3. UVA1629 Cake slicing

    题目传送门 直接暴力定义f[x1][y1][x2][y2]是使对角为\((x1, y1),(x2, y2)\)这个子矩形满足要求的最短切割线长度 因为转移顺序不好递推,采用记忆化搜索 #include ...

  4. 使用Xcode过程中遇到的问题

    前言:记录一下使用Xcode过程中遇到的问题 1.关于开发者的Team的问题,是选用自己的个人Team还是选用公司的付费的Team(本机环境:Xcode9 + iPad :iOS11.0.3) 问题: ...

  5. common-fileupload组件实现java文件上传和下载

    简介:文件上传和下载是java web中常见的操作,文件上传主要是将文件通过IO流传放到服务器的某一个特定的文件夹下,而文件下载则是与文件上传相反,将文件从服务器的特定的文件夹下的文件通过IO流下载到 ...

  6. ios swift 里面关于变量 常量 可选类型 控制流的一些心得

    //swift 里面没有头文件和实现文件.只有一个.swift文件 //swift 里面没有main的概念,程序从main.swift开始执行 //swift 每一条执行语句可以不用分号结束,多条语句 ...

  7. Spring Boot 前世今生

    Spring Boot 2.0 的推出又激起了一阵学习 Spring Boot 热,就单从我个人的博客的访问量大幅增加就可以感受到大家对学习 Spring Boot 的热情,那么在这么多人热衷于学习 ...

  8. Java读取各种文件格式内容

    所需的jar包哦也不要太记得了,大家可以搜搜,直接上代码: import java.io.BufferedInputStream; import java.io.File; import java.i ...

  9. Memory loss【记忆缺失】

    Memory Loss Losing your ability to think and remember is pretty scary. We know the risk of dementia ...

  10. openstack源

    为了红帽系在云计算的市场份额,CentOS推出了官方openstack软件源. http://mirrors.ustc.edu.cn/centos/6/cloud/x86_64/openstack-j ...