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 ...
随机推荐
- Sqlserver Sequence操作
USE [database_test] GO --创建SEQUENCE CREATE SEQUENCE defaultSequence AS INT --设置开始行 START --自增量 INCRE ...
- Use Reentrant Functions for Safer Signal Handling(译:使用可重入函数进行更安全的信号处理)
Use Reentrant Functions for Safer Signal Handling 使用可重入函数进行更安全的信号处理 How and when to employ reentranc ...
- key是数字的对象集合
整理如下: let data = {3: '影视', 4: '音乐', 5: '广场舞', 6: '游戏', 7: '综艺', 8: '动漫', 9: '翻唱', 10: '生活', 11: '美食' ...
- sencha touch Button Select(点击按钮进行选择)扩展
此扩展基于官方selectfield控件修改而来,变动并不大,使用方法类似. 代码如下: Ext.define('ux.SelectBtn', { extend: 'Ext.Button', xtyp ...
- Apache Server Status详解
Apache的日志如果靠分析日志或者查看服务器进程来监视Apache运行状态的话,比较繁冗.不过在Apache 1.3.2及以后的版本中就自带一个查看Apache状态的功能模块server-statu ...
- CreateTimerQueueTimer在DllMain中调用导致的loader lock
开发一个COM组件在Windows 7上注册成功,但是Windows XP SP3版本却导致regsvr32.exe进程挂起.用WinDbg查看发现提示: Break- seconds... WARN ...
- The request associated with the AsyncContext has already completed processing
Some time ago there was a problem with the servlet3.0, is in servlet in asynchronous processing data ...
- CentOS 添加环境变量
1.修改环境变量需要修改/etc/profile export PATH="$PATH:/usr/src/ruby-1.9.3-p0/ruby:/usr/local/bin/gem&qu ...
- 【CF850E】Random Elections FWT
[CF850E]Random Elections 题意:有n位选民和3位预选者A,B,C,每个选民的投票方案可能是ABC,ACB,BAC...,即一个A,B,C的排列.现在进行三次比较,A-B,B-C ...
- 仿QQ、微信翻页查看聊天记录
主界面MainActivity.class public class MainActivity extends Activity implements OnScrollListener{ privat ...