#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <string>
#include <math.h> using namespace std; const double eps = 1e-8;
int sgn(double x)
{
if(fabs(x) < eps)return 0;
if(x < 0) return -1;
else return 1;
}
struct Point
{
double x,y;
Point(){}
Point(double _x,double _y)
{
x = _x;y = _y;
}
Point operator -(const Point &b)const
{
return Point(x - b.x,y - b.y);
}
double operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
double operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
};
struct Line
{
Point s,e;
Line(){}
Line(Point _s,Point _e)
{
s = _s;e = _e;
}
};
//判断线段相交
bool inter(Line l1,Line l2)
{
return
max(l1.s.x,l1.e.x) >= min(l2.s.x,l2.e.x) &&
max(l2.s.x,l2.e.x) >= min(l1.s.x,l1.e.x) &&
max(l1.s.y,l1.e.y) >= min(l2.s.y,l2.e.y) &&
max(l2.s.y,l2.e.y) >= min(l1.s.y,l1.e.y) &&
sgn((l2.s-l1.s)^(l1.e-l1.s))*sgn((l2.e-l1.s)^(l1.e-l1.s)) <= 0 &&
sgn((l1.s-l2.s)^(l2.e-l2.s))*sgn((l1.e-l2.s)^(l2.e-l2.s)) <= 0;
}
double dist(Point a,Point b)
{
return sqrt((b-a)*(b-a));
}
const int MAXN = 100;
Line line[MAXN];
double dis[MAXN][MAXN];
const double INF = 1e20;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n;
double x,y1,y2,y3,y4;
while(scanf("%d",&n) == 1)
{
if(n == -1) break;
for(int i = 1;i <= n;i++)
{
scanf("%lf%lf%lf%lf%lf",&x,&y1,&y2,&y3,&y4);
line[2*i-1] = Line(Point(x,y1),Point(x,y2));
line[2*i] = Line(Point(x,y3),Point(x,y4));
}
for(int i = 0;i <= 4*n+1;i++)
for(int j = 0;j <= 4*n+1;j++)
{
if(i == j)dis[i][j] = 0;
else dis[i][j] = INF;
}
for(int i = 1;i <= 4*n;i++)
{
int lid = (i+3)/4;
bool flag = true;
Point tmp;
if(i&1)tmp = line[(i+1)/2].s;
else tmp = line[(i+1)/2].e;
for(int j = 1;j < lid;j++)
if(inter(line[2*j-1],Line(Point(0,5),tmp)) == false
&& inter(line[2*j],Line(Point(0,5),tmp)) == false)
flag = false;
if(flag)dis[0][i] =dis[i][0] = dist(Point(0,5),tmp);
flag = true;
for(int j = lid+1;j <= n;j++)
if(inter(line[2*j-1],Line(Point(10,5),tmp)) == false
&& inter(line[2*j],Line(Point(10,5),tmp)) == false)
flag = false;
if(flag)dis[i][4*n+1] =dis[4*n+1][i] = dist(Point(10,5),tmp);
}
for(int i = 1;i <= 4*n;i++)
for(int j = i+1;j <=4*n;j++)
{
int lid1 = (i+3)/4;
int lid2 = (j+3)/4;
bool flag = true;
Point p1,p2;
if(i&1)p1 = line[(i+1)/2].s;
else p1 = line[(i+1)/2].e;
if(j&1)p2 = line[(j+1)/2].s;
else p2 = line[(j+1)/2].e;
for(int k = lid1+1;k < lid2;k++)
if(inter(line[2*k-1],Line(p1,p2)) == false
&& inter(line[2*k],Line(p1,p2)) == false)
flag = false;
if(flag) dis[i][j] = dis[j][i] = dist(p1,p2);
}
bool flag = true;
for(int i = 1;i <= n;i++)
if(inter(line[2*i-1],Line(Point(0,5),Point(10,5))) == false
&& inter(line[2*i],Line(Point(0,5),Point(10,5))) == false)
flag = false;
if(flag)dis[0][4*n+1] = dis[4*n+1][0] = 10;
for(int k = 0;k <= 4*n+1;k++)
for(int i = 0;i <= 4*n+1;i++)
for(int j = 0;j <= 4*n+1;j++)
if(dis[i][k] + dis[k][j] < dis[i][j])
dis[i][j] = dis[i][k] + dis[k][j];
printf("%.2lf\n",dis[0][4*n+1]);
} return 0;
}

  

POJ 1556 The Doors(线段交+最短路)的更多相关文章

  1. POJ 1556 The Doors 线段交 dijkstra

    LINK 题意:在$10*10$的几何平面内,给出n条垂直x轴的线,且在线上开了两个口,起点为$(0, 5)$,终点为$(10, 5)$,问起点到终点不与其他线段相交的情况下的最小距离. 思路:将每个 ...

  2. POJ 1556 - The Doors 线段相交不含端点

    POJ 1556 - The Doors题意:    在 10x10 的空间里有很多垂直的墙,不能穿墙,问你从(0,5) 到 (10,5)的最短距离是多少.    分析:        要么直达,要么 ...

  3. POJ 1556 The Doors 线段判交+Dijkstra

    The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6734   Accepted: 2670 Descrip ...

  4. POJ 1556 The Doors --几何,最短路

    题意: 给一个正方形,从左边界的中点走到右边界的中点,中间有一些墙,问最短的距离是多少. 解法: 将起点,终点和所有墙的接触到空地的点存下来,然后两两之间如果没有线段(墙)阻隔,就建边,最后跑一个最短 ...

  5. POJ 1556 计算几何 判断线段相交 最短路

    题意: 在一个左下角坐标为(0,0),右上角坐标为(10,10)的矩形内,起点为(0,5),终点为(10,5),中间会有许多扇垂直于x轴的门,求从起点到终点在能走的情况下的最短距离. 分析: 既然是求 ...

  6. POJ 1556 The Doors(线段交+最短路)

    The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5210   Accepted: 2124 Descrip ...

  7. POJ 3304 Segments 基础线段交判断

    LINK 题意:询问是否存在直线,使得所有线段在其上的投影拥有公共点 思路:如果投影拥有公共区域,那么从投影的公共区域作垂线,显然能够与所有线段相交,那么题目转换为询问是否存在直线与所有线段相交.判断 ...

  8. POJ 1556 The Doors【最短路+线段相交】

    思路:暴力判断每个点连成的线段是否被墙挡住,构建图.求最短路. 思路很简单,但是实现比较复杂,模版一定要可靠. #include<stdio.h> #include<string.h ...

  9. 简单几何(线段相交+最短路) POJ 1556 The Doors

    题目传送门 题意:从(0, 5)走到(10, 5),中间有一些门,走的路是直线,问最短的距离 分析:关键是建图,可以保存所有的点,两点连通的条件是线段和中间的线段都不相交,建立有向图,然后用Dijks ...

随机推荐

  1. PHP避免刷新页面重复提交

    PHP避免刷新页面重复提交 2013-07-09 15:27 匿名 | 浏览 3567 次 编程语言 情景:从html提交数据到x.php 在x.php中$_POST数据写库并且显示,当x.php刷新 ...

  2. Json数据,转换规则,

    JSON数据转换,规则是遇见json 中的{},则是数组[],遇见name:value,则是'key'=>'value', 但是不带键值的数组如['xxxxxx'],json_encode后仍然 ...

  3. 越狱Season 1-Episode 4: Cute Poison

    Season 1, Episode 4: Cute Poison [Previously on Prison Break] previously: 以前地 前情提要 -Burrows: I didn' ...

  4. 论文阅读之:Is Faster R-CNN Doing Well for Pedestrian Detection?

    Is Faster R-CNN Doing Well for Pedestrian Detection? ECCV 2016   Liliang Zhang & Kaiming He 原文链接 ...

  5. Python-描述符

    Python中包含了许多内建的语言特性,它们使得代码简洁且易于理解.这些特性包括列表/集合/字典推导式,属性(property).以及装饰器(decorator).对于大部分特性来说,这些“中级”的语 ...

  6. 在apache连接多php的时候遇到了问题,怎么切换多个php版本?

    PHP 在apache连接多php的时候遇到了问题,怎么切换多个php版本? 我的机器里面有一个apache2.2.22,但是有两个php,5.3.10和5.4.3,5.3.10是mac os x带的 ...

  7. js中退出语句break,continue和return 比较

    js中退出语句break,continue和return 比较 在 break,continue和return 三个关键字中, break,continue是一起的,return 是函数返回语句,但是 ...

  8. OCR文字识别软件许可文件被误删了怎么办

    使用任何一款软件,都会有误操作的情况发生,比如清理文件时一不小心删除了许可文件,对于ABBYY FineReader 12这样一款OCR文字识别软件,因失误错误删除了许可文件该怎么办呢?今天就来给大家 ...

  9. 关于a标签的target属性

    超级链接a的target属性已经是不被新规范支持了,其值有四个保留字: 1._blank      <a href="document.html" target=" ...

  10. unity,生成的mac版游戏切场景时卡死解法

    unity版本为5.1.1,在编辑器里运行没问题,build出的windows版运行也没问题,但build出的mac版在个别场景切换时会卡死,通过查看log(查看build版本log的方法参考:htt ...