poj 2983(最短路 差分约束)

本文介绍了一种算法,用于验证给定的防御站布局信息是否可靠。通过解析精确和模糊的位置提示,利用差分系统和SPFA算法判断布局的可行性。

Is the Information Reliable?

Time Limit: 3000MS Memory Limit: 131072K
Total Submissions: 15783 Accepted: 4893

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
题意:银河系中有n个防御站排成一条直线,给定m条信息,每条信息的格式如下。
P A B X代表A站在B站北方X光年处。
V A B 代表A站在B站北方,而且距离至少为1光年。
问是否存在这样的一个防御战排列满足上述要求,是输出Reliable,否输出 Unreliable。

 

从P  A  B  X得到的差分系统为

dist[A] - dist[B] >= X  &&  dist[A] - dist[B] <= X

等价于
dist[B] <= dist[A] - X  &&  dist[A] <= dist[B] + X

从V  A  B得到的差分系统为
dist[A] >= dist[B] +1

等价于
dist[B] <= dist[A] -1 
 

#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstring>


using namespace std;
const int N=1e5+10;
const int inf=0x3f3f3f3f;
struct node
{
	int to,dis,next;
}edge[N<<2];
int cnt,head[N];
void addedge(int from,int to,int dis)
{
	edge[cnt].to=to;
	edge[cnt].dis=dis;
	edge[cnt].next=head[from];
	head[from]=cnt++;
}

int dis[N];
bool vis[N];
int num[N];
bool spfa(int n)
{
	memset(num,0,sizeof(num));
	memset(vis,false,sizeof(vis));
	memset(dis,inf,sizeof(dis));
	dis[0]=0;
	vis[0]=true;
	queue<int>Q;
	Q.push(0);
	while(!Q.empty()){
		int u=Q.front();
		Q.pop();
		vis[u]=false;
		//cout<<"u="<<u<<endl;
		for(int i=head[u];i!=-1;i=edge[i].next){
			int to=edge[i].to;
			if(dis[to]>dis[u]+edge[i].dis){
				dis[to]=dis[u]+edge[i].dis;
				if(!vis[to]){
					vis[to]=true;
					Q.push(to);
					if(++num[to]>n) return false;
				}
			}
		}
	} 
	return true;
}
int main()
{

	int n,m;
	while(scanf("%d %d",&n,&m)==2){
		memset(head,-1,sizeof(head));
		cnt=0;
		for(int i=0;i<m;i++){
			char t[10];
			int a,b;
			scanf("%s %d %d",t,&a,&b);
			if(t[0]=='P'){
				int c;
				scanf("%d",&c);
				addedge(a,b,-c);
				addedge(b,a,c);
			}
			else{
				addedge(a,b,-1);
			}
		}
		for(int i=1;i<=n;i++){
			addedge(0,i,0);
		}
		if(spfa(n)){
			puts("Reliable");
		}
		else{
			puts("Unreliable");
		}
	}
	return 0;
}

 

【无人机】基于改进粒子群算法的无人机路径规划研究[和遗传算法、粒子群算法进行比较](Matlab代码实现)内容概要:本文围绕基于改进粒子群算法的无人机路径规划展开研究,重点探讨了在复杂环境中利用改进粒子群算法(PSO)实现无人机三维路径规划的方法,并将其与遗传算法(GA)、标准粒子群算法等传统优化算法进行对比分析。研究内容涵盖路径规划的多目标优化、避障策略、航路点约束以及算法收敛性和寻优能力的评估,所有实验均通过Matlab代码实现,提供了完整的仿真验证流程。文章还提到了多种智能优化算法在无人机路径规划中的应用比较,突出了改进PSO在收敛速度和全局寻优方面的优势。; 适合人群:具备一定Matlab编程基础和优化算法知识的研究生、科研人员及从事无人机路径规划、智能优化算法研究的相关技术人员。; 使用场景及目标:①用于无人机在复杂地形或动态环境下的三维路径规划仿真研究;②比较不同智能优化算法(如PSO、GA、蚁群算法、RRT等)在路径规划中的性能差异;③为多目标优化问题提供算法选型和改进思路。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注算法的参数设置、适应度函数设计及路径约束处理方式,同时可参考文中提到的多种算法对比思路,拓展到其他智能优化算法的研究与改进中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值