POJ2983 Is the Information Reliable?
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=267#problem/B
Time Limit:3000MS Memory Limit:131072KB 64bit IO Format:%I64d & %I64u
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
Reliable
还是那句话:差分约束条件题目的难点是“怎么找到问题的约束条件”。
这题输入的边有两种格式:
1. 边长确定,即xi - xj = b; 可以转化成 xi - xj <= b 和 xi - xj >=b (即 xj - xi <= -b).
2. 边长不定,xi - xj >= 1; 可以转化成 xj - xi <= -1;
da-db>=x;
da-db<=x;
==>da>=db+x;
db>=da-x;
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
int n,m,tt;
struct node
{
int x,y,z;
} q[];
int dis[];
void BF()
{
int flag;
memset(dis,,sizeof(dis));
for(int i=; i<=n; i++)
{
flag=;
for(int j=; j<tt; j++)
{
if(dis[q[j].x]<dis[q[j].y]+q[j].z)
{
dis[q[j].x]=dis[q[j].y]+q[j].z;
flag=;
}
}
if(flag==) break;
}
if(flag)
cout<<"Unreliable"<<endl;
else
cout<<"Reliable"<<endl;
return;
}
int main()
{
char ch;
int xx,yy,zz;
while(scanf("%d%d",&n,&m)!=EOF)
{
tt=;
while(m--)
{
getchar();
scanf("%c",&ch);
if(ch=='P')
{
scanf("%d%d%d",&xx,&yy,&zz);
q[tt].x=xx;
q[tt].y=yy;
q[tt++].z=zz;
q[tt].x=yy;
q[tt].y=xx;
q[tt++].z=-zz;
}
else if(ch=='V')
{
scanf("%d%d",&xx,&yy);
q[tt].x=xx;
q[tt].y=yy;
q[tt++].z=;
}
}
BF();
}
return ;
}
POJ2983 Is the Information Reliable?的更多相关文章
- poj2983--Is the Information Reliable?(差分约束)
Is the Information Reliable? Time Limit: 3000MS Memory Limit: 131072K Total Submissions: 11125 A ...
- POJ 之 Is the Information Reliable?
B - Is the Information Reliable? Time Limit:3000MS Memory Limit:131072KB 64bit IO Format:%I6 ...
- 【POJ 2983】Is the Information Reliable?(差分约束系统)
id=2983">[POJ 2983]Is the Information Reliable? (差分约束系统) Is the Information Reliable? Time L ...
- Is the Information Reliable? -POJ2983差分约束
Time Limit: 3000MS Memory Limit: 131072K Description The galaxy war between the Empire Draco and the ...
- 【poj2983】 Is the Information Reliable?
http://poj.org/problem?id=2983 (题目链接) 一个SB错误TLE了半个小时... 题意 一条直线上有n个点,给出m条信息,若为P则表示点A在点B的北方X米,若为V则表示A ...
- 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
Description The galaxy war between the Empire Draco and the Commonwealth of Zibu broke out 3 years a ...
- 图论--差分约束--POJ 2983--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? 差分约束
裸差分约束. //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #i ...
随机推荐
- 【前端开发】 JS面试题整理
1.截取字符串abcdace的acealert('abcdace'.substring(4)); 2.规避javascript多人开发函数重名问题命名空间封闭空间js模块化mvc(数据层.表现层.控制 ...
- 云计算设计模式(二十三)——Throttling节流模式
云计算设计模式(二十三)——Throttling节流模式 控制由应用程序使用,一个单独的租户或整个服务的一个实例的资源的消耗.这种模式可以允许系统继续运行并满足服务水平协议,即使当增加需求的资源放置一 ...
- 三元组顺序结构实现稀疏矩阵相加,行序优先(Java语言描述)
不用十字链表也可以稀疏矩阵相加时间复杂度最坏情况达到O(tuA + tuB);思路比较简单就不赘述了,代码如下: 三元组: package 行逻辑链接的顺序表实现稀疏矩阵的相乘; public cla ...
- Android 验证APK是否已经签名或是否是Debug签名
https://source.android.google.cn/ http://www.android-doc.com/tools/publishing/app-signing.html Signi ...
- 题目1208:10进制 VS 2进制(进制转换以及大数保存问题)
题目链接:http://ac.jobdu.com/problem.php?pid=1208 详细链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- 跟bWAPP学WEB安全(PHP代码)--HTML注入和iFrame注入
背景 这里讲解HTML注入和iFrame注入,其他的本质都是HTML的改变.那么有人会问,XSS与HTML注入有啥区别呢?其实本质上都是没有区别的,改变前端代码,来攻击客户端,但是XSS可以理解为注入 ...
- 利用 bugly 分析应用崩溃
Bugly-Crash监控能让我们及时的掌控应用的Crash,并快速修复.这种情况就在于我们把应用发布出去了,但是用户那边有着各种各样我们想象不到的系统崩溃,我们无法通过简单的控制台捕获错误信息和崩溃 ...
- LCA最近公共祖先(least common ancestors)
#include"stdio.h" #include"string.h" #include"iostream" #include" ...
- eclipse配置Js环境spket
网上下载spket-1.6.16.jar破解版(目前最新版本) 1.如果你的JDK在1.6以上,可以直接双击spket-1.6.16.jar运行安装. 其它,使用命令行方式.(注意:自己切换命令行到s ...
- ubuntu部署nginx
先更新本机内置的程序. sudo apt-get updatesudo apt-get upgrade再判断系统是否内置了add-apt-repository命令,如果没有执行下列命令安装 sudo ...