【POJ】1556 The Doors(计算几何基础+spfa)

本文介绍了一种在含有障碍物的房间中寻找从起点到终点的最短路径的方法。通过构建图并使用SPFA算法来解决该问题,文章详细解释了如何处理墙壁和门等障碍物,并给出了具体的实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://poj.org/problem?id=1556

首先路径的每条线段一定是端点之间的连线。证明?这是个坑...反正我是随便画了一下图然后就写了..

然后re是什么节奏?我记得我开够了啊...然后再开大点才a...好囧啊.

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define error(x) (!(x)?puts("error"):0)
#define rdm(x, i) for(int i=ihead[x]; i; i=e[i].next)
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }

const double eps=1e-6;
int dcmp(double x) { return abs(x)<eps?0:(x<0?-1:1); }
struct ipoint { double x, y; };
double icross(ipoint &a, ipoint &b, ipoint &c) {
	static double x1, x2, y1, y2;
	x1=a.x-c.x; y1=a.y-c.y;
	x2=b.x-c.x; y2=b.y-c.y;
	return x1*y2-x2*y1;
}
int ijiao(ipoint &p1, ipoint &p2, ipoint &q1, ipoint &q2) {
	return (dcmp(icross(p1, q1, q2))^dcmp(icross(p2, q1, q2)))==-2 &&
		   (dcmp(icross(q1, p1, p2))^dcmp(icross(q2, p1, p2)))==-2;
}

const int N=1000;
struct dat { int next, to; double w; }e[N<<2];
int ihead[N], cnt;
void add(int u, int v, double w) {
	e[++cnt].next=ihead[u]; ihead[u]=cnt; e[cnt].to=v; e[cnt].w=w;
}
double spfa(int s, int t, int n) {
	static double d[N];
	static int q[N], front, tail, u, v;
	static bool vis[N];
	front=tail=0;
	for1(i, 0, n) vis[i]=0, d[i]=1e99;
	d[s]=0; q[tail++]=s; vis[s]=1;
	while(front!=tail) {
		u=q[front++]; if(front==N) front=0; vis[u]=0;
		rdm(u, i) if(d[v=e[i].to]+eps>d[u]+e[i].w) {
			d[v]=d[u]+e[i].w;
			if(!vis[v]) {
				vis[v]=1;
				if(d[v]<d[q[front]]+eps) {
					--front; if(front<0) front+=N;
					q[front]=v;
				}
				else { q[tail++]=v; if(tail==N) tail=0; }
			}
		}
	}
	return d[t];
}

ipoint p[N], line[N*3][2];
int n, pn, ln;

bool check(ipoint &x, ipoint &y) {
	for1(i, 1, ln) if(ijiao(x, y, line[i][0], line[i][1])) return false;
	return true;
}
double sqr(double x) { return x*x; }
double dis(ipoint &x, ipoint &y) { return sqrt(sqr(x.x-y.x)+sqr(x.y-y.y)); }

int main() {
	while(read(n), n!=-1) {
		ln=0; pn=0;
		++pn; p[pn].x=0; p[pn].y=5;
		++pn; p[pn].x=10; p[pn].y=5;
		static double rx, ry[4];
		while(n--) {
			scanf("%lf", &rx);
			rep(k, 4) scanf("%lf", &ry[k]);
			++ln; line[ln][0]=(ipoint){rx, 0};		line[ln][1]=(ipoint){rx, ry[0]};
			++ln; line[ln][0]=(ipoint){rx, ry[1]};	line[ln][1]=(ipoint){rx, ry[2]};
			++ln; line[ln][0]=(ipoint){rx, ry[3]};	line[ln][1]=(ipoint){rx, 10};
			rep(k, 4) ++pn, p[pn].x=rx, p[pn].y=ry[k];
		}
		for1(i, 1, pn) for1(j, 1, pn) if(i!=j && check(p[i], p[j])) add(i, j, dis(p[i], p[j]));
		printf("%.2f\n", spfa(1, 2, pn));

		memset(ihead, 0, sizeof(int)*(pn+1));
		cnt=0;
	}
	return 0;
}

  

 


 

 

Description

You are to find the length of the shortest path through a chamber containing obstructing walls. The chamber will always have sides at x = 0, x = 10, y = 0, and y = 10. The initial and final points of the path are always (0, 5) and (10, 5). There will also be from 0 to 18 vertical walls inside the chamber, each with two doorways. The figure below illustrates such a chamber and also shows the path of minimal length. 

Input

The input data for the illustrated chamber would appear as follows. 


4 2 7 8 9 
7 3 4.5 6 7 

The first line contains the number of interior walls. Then there is a line for each such wall, containing five real numbers. The first number is the x coordinate of the wall (0 < x < 10), and the remaining four are the y coordinates of the ends of the doorways in that wall. The x coordinates of the walls are in increasing order, and within each line the y coordinates are in increasing order. The input file will contain at least one such set of data. The end of the data comes when the number of walls is -1. 

Output

The output should contain one line of output for each chamber. The line should contain the minimal path length rounded to two decimal places past the decimal point, and always showing the two decimal places past the decimal point. The line should contain no blanks.

Sample Input

1
5 4 6 7 8
2
4 2 7 8 9
7 3 4.5 6 7
-1

Sample Output

10.00
10.06

Source

JFM7VX690T型SRAM型现场可编程门阵列技术手册主要介绍的是上海复旦微电子集团股份有限公司(简称复旦微电子)生产的高性能FPGA产品JFM7VX690T。该产品属于JFM7系列,具有现场可编程特性,集成了功能强大且可以灵活配置组合的可编程资源,适用于实现多种功能,如输入输出接口、通用数字逻辑、存储器、数字信号处理和时钟管理等。JFM7VX690T型FPGA适用于复杂、高速的数字逻辑电路,广泛应用于通讯、信息处理、工业控制、数据中心、仪表测量、医疗仪器、人工智能、自动驾驶等领域。 产品特点包括: 1. 可配置逻辑资源(CLB),使用LUT6结构。 2. 包含CLB模块,可用于实现常规数字逻辑和分布式RAM。 3. 含有I/O、BlockRAM、DSP、MMCM、GTH等可编程模块。 4. 提供不同的封装规格和工作温度范围的产品,便于满足不同的使用环境。 JFM7VX690T产品系列中,有多种型号可供选择。例如: - JFM7VX690T80采用FCBGA1927封装,尺寸为45x45mm,使用锡银焊球,工作温度范围为-40°C到+100°C。 - JFM7VX690T80-AS同样采用FCBGA1927封装,但工作温度范围更广,为-55°C到+125°C,同样使用锡银焊球。 - JFM7VX690T80-N采用FCBGA1927封装和铅锡焊球,工作温度范围与JFM7VX690T80-AS相同。 - JFM7VX690T36的封装规格为FCBGA1761,尺寸为42.5x42.5mm,使用锡银焊球,工作温度范围为-40°C到+100°C。 - JFM7VX690T36-AS使用锡银焊球,工作温度范围为-55°C到+125°C。 - JFM7VX690T36-N使用铅锡焊球,工作温度范围与JFM7VX690T36-AS相同。 技术手册中还包含了一系列详细的技术参数,包括极限参数、推荐工作条件、电特性参数、ESD等级、MSL等级、重量等。在产品参数章节中,还特别强调了封装类型,包括外形图和尺寸、引出端定义等。引出端定义是指对FPGA芯片上的各个引脚的功能和接线规则进行说明,这对于FPGA的正确应用和电路设计至关重要。 应用指南章节涉及了FPGA在不同应用场景下的推荐使用方法。其中差异说明部分可能涉及产品之间的性能差异;关键性能对比可能包括功耗与速度对比、上电浪涌电流测试情况说明、GTH Channel Loss性能差异说明、GTH电源性能差异说明等。此外,手册可能还提供了其他推荐应用方案,例如不使用的BANK接法推荐、CCLK信号PCB布线推荐、JTAG级联PCB布线推荐、系统工作的复位方案推荐等,这些内容对于提高系统性能和稳定性有着重要作用。 焊接及注意事项章节则针对产品的焊接过程提供了指导,强调焊接过程中的注意事项,以确保产品在组装过程中的稳定性和可靠性。手册还明确指出,未经复旦微电子的许可,不得翻印或者复制全部或部分本资料的内容,且不承担采购方选择与使用本文描述的产品和服务的责任。 上海复旦微电子集团股份有限公司拥有相关的商标和知识产权。该公司在中国发布的技术手册,版权为上海复旦微电子集团股份有限公司所有,未经许可不得进行复制或传播。 技术手册提供了上海复旦微电子集团股份有限公司销售及服务网点的信息,方便用户在需要时能够联系到相应的服务机构,获取最新信息和必要的支持。同时,用户可以访问复旦微电子的官方网站(***以获取更多产品信息和公司动态。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值