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 ...
随机推荐
- Win8交互UX——键盘交互
设计用户可以通过硬件键盘.屏幕键盘或触摸键盘交互的 Windows 应用商店应用. 本主题介绍键盘交互的设计注意事项.有关实现键盘交互的信息,请参阅响应键盘输入. 键盘交互 键盘输入是 Windows ...
- LinQ实战学习笔记(一) LINQ to (Objects, XML, SQL) 入门初步
LINQ对于笔者来说, 优美而浓缩的代码让人震惊. 研究LINQ就是在艺术化自己的代码. 之前只是走马观花学会了基本的语法, 但是经常在CSDN看到令人惊讶自叹不如的LINQ代码, 还是让人羡慕嫉妒恨 ...
- SSL & TLS & STARTTLS
https://www.fastmail.com/help/technical/ssltlsstarttls.html SSL vs TLS vs STARTTLS There's often qui ...
- 从零开始学习Hadoop--第4章 序列化(转载)
作者对序列化的描述浅显易懂!(https://www.douban.com/note/313096752/) 1. 序列化从头说 在面向对象程序设计中,类是个很重要的概念.所谓“类”,可以将它想像成建 ...
- 题目1448:Legal or Not(有向无环图判断——拓扑排序问题)
题目链接:http://ac.jobdu.com/problem.php?pid=1448 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- oracle索引优化
零.概述 在这之前,一直都是使用mysql来进行开发或者部署.最近及今后很长一段时间都要使用oracle,今天和同事也遇到一个oracle 慢查询问题.查了很多资料,这里记录备忘.持续更新ing... ...
- apache两种工作模式详解
prefork模式 这个多路处理模块(MPM)实现了一个非线程型的.预派生的web服务器,它的工作方式类似于Apache 1.3.它适合于没有线程安全库,需要避免线程兼容性问题的系统.它是要求将每个请 ...
- Word 2013无法启用Restrict Editing解决方法
当前文档可能是Mail Merge Letter type document,MAILINGS -> Start Mail Merge -> Normal Word Document保存即 ...
- pycharm的版本问题
1.分类: 专业版是收费的 Professional 教育版是免费 edu https://www.jetbrains.com/pycharm-edu/whatsnew/ 社区版是免费的 Free C ...
- mac设置文件权限问题
在使用mac时,经常我们遇到相关文件不能使用的情况,其实大多数情况都是,文件权限问题. 文件或目录的访问权限分为只读,只写和可执行三种.以文件为例,只读权限表示只允许读其内容,而禁止对其做任何的更改操 ...