裸差分约束. //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include<sstream> #include<cmath> #include<…
题目地址:POJ 2983 题意:有N个车站.给出一些点的精确信息和模糊信息.精确信息给出两点的位置和距离.模糊信息给出两点的位置.但距离大于等于一.试确定是否全部的信息满足条件. 思路:事实上就是让你推断是否存在负环.好久才看明确.对于精确消息.能够得出两个差分公式:dis[v] <= dist[u] - w  &&  dist[u] <= dist[v] + w.对于模糊信息.能够得出dis[v] <= dis[u] -1. PS:做差分约束感觉还是Bellman_f…
http://poj.org/problem?id=2983 题意:给出M条信息,判断这些信息的正确性.(1)V A B :表示A,B之间的距离>=1; (2)P A B X :表示A B之间的距离为x. 思路:dis[i]表示i到原点的距离,由(1)知 dis[A]<=dis[B]-1 即B->A之间有一条边,权值为-1:由(2)知: dis[A]<=dis[B]-x && dis[B] <= dis[A]+x,即A->B的权值为-x,B->A的…
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…
题意:有n个站排成一列,针对每个站的位置与距离关系,现有多个约束条件,约束条件分两种:(1)确定的.明确说明站a距离站b多少个单位距离.(2)不确定的.只知道a在b的左边至少1个单位距离.  根据已知条件,问有没有冲突?不冲突则输出reliable. 思路: 第2种条件比较好确定,如果知道如何用最短路解差分约束的话. 问题在第1种,明确地说明了距离,怎么办?拆成两条式子,比如 dis(a,b)=c,那么可以写成 b-a>=c ,b-a<=c 这样,只要满足这两个条件,原来明确说明的距离也会成立…
题目大意:有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判断负权回路的方法,记录每个点进队次数,超过点的数目即存在负权回路. 代码…
http://poj.org/problem?id=2983 题目大意: 星际大战开始了.你购买了情报,需要判断它的准确性.已知地方的根据地在由南向北排成一条直线.P A B X,表示A在B北面距离X光年的地方,另一种是V A B,表示只知道A在B的北面至少1光年的地方. 思路: 可转化为差分约束. 对于P A B X来说因为A-B=X (因为他们相距X光年,我们取北边为正方向) 可以记做:  A-B >=X &&  A-B<=X,即A-B>=X && B…
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 defe…
http://poj.org/problem?id=2983 题意:N 个 defense stations,M条消息,消息有精确和模糊之分,若前边为P.则为精确消息,有两个defense stations和他们之间的距离,若为P A B X 则是精确消息,并且A在B北边X光年远,V A B则是模糊消息,A在B北边,不知道距离,但至少是1光年远. 思路 :这个题要转化成差分约束.因为dist[a]-dist[b] = x,所以转化成差分约束x<=dist[a]-dist[b]<=x ,模糊消息…
id=2983">[POJ 2983]Is the Information Reliable? (差分约束系统) Is the Information Reliable? Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 12244   Accepted: 3861 Description The galaxy war between the Empire Draco and the Commonwealth of…