The Doors

Time Limit: 1000 MS Memory Limit: 10000 KB

64-bit integer IO format: %I64d , %I64u   Java class name: Main

[Submit] [Status] [Discuss]

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.
2  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
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <cmath> using namespace std;
#define maxx 100
#define INF 10000000 struct Node
{
double x;
double y;
} p[maxx]; ///每扇门的终点 起点 和门的两个端点的平面坐标 struct EDGE
{
int u;
int v;
} Edge[maxx*maxx]; ///存构造的边 因为之前是孤立的点 int n; ///n个墙
double wX[]; ///输入每堵墙的横坐标
double py[][]; ///每堵墙横坐标对应的纵坐标 0 1 2 3 double g[maxx][maxx]; ///存邻接矩阵 配合dis[]的
double dis[maxx]; ///beg到其他点的最短距离 int Psize; ///边的数量
int Esize; ///点的数量 double Dis(Node a,Node b) ///计算亮点之间的距离
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} double cross(double x1,double y1,double x2,double y2,double x3,double y3) ///判断(x3,y3)与(x1,y1)(x2,y2)是否交叉
{
return (x2-x1)*(y3-y1)-(x3-x1)*(y2-y1);
} bool IsOk(Node a,Node b) ///判断两点之间是否可以连线
{
if(a.x>=b.x)
return false;
bool falg=true;
int i=;
while(wX[i]<=a.x&&i<n)
i++;
while(wX[i]<b.x&&i<n)
{
if(cross(a.x,a.y,b.x,b.y,wX[i],)*cross(a.x,a.y,b.x,b.y,wX[i],py[i][])<
||cross(a.x,a.y,b.x,b.y,wX[i],py[i][])*cross(a.x,a.y,b.x,b.y,wX[i],py[i][])<
||cross(a.x,a.y,b.x,b.y,wX[i],py[i][])*(cross(a.x,a.y,b.x,b.y,wX[i],))<)
{
falg=false;
break;
}
i++;
}
return falg;
} double Bellman(int beg,int end)
{
for(int i=;i<maxx;i++)
dis[i]=INF;
dis[beg]=;
bool EX=true;
for(int i=;i<=Psize&&EX;i++)
{
EX=false;
for(int j=;j<Esize;j++)
{
if(dis[Edge[j].u]<INF&&dis[Edge[j].v]>(dis[Edge[j].u]+g[Edge[j].u][Edge[j].v]))
{
dis[Edge[j].v]=(dis[Edge[j].u]+g[Edge[j].u][Edge[j].v]);
EX=true;
}
}
}
return dis[end];
} int main()
{
while(scanf("%d",&n)!=EOF)
{
if(n==-)
break;
p[].x=;
p[].y=;
Psize=;
for(int i=; i<n; i++)
{
cin>>wX[i];
for(int j=; j<; j++)
{
p[Psize].x=wX[i];
cin>>p[Psize].y;
py[i][j]=p[Psize].y;
Psize++;
}
}
p[Psize].x=;
p[Psize].y=;
for(int i=; i<=Psize; i++)
{
for(int j=; j<=Psize; j++)
{
g[i][j]==INF;
}
}
Esize=;
for(int i=; i<=Psize; i++)
{
for(int j=i+; j<=Psize; j++)
{
if(IsOk(p[i],p[j]))
{
g[i][j]=Dis(p[i],p[j]);
Edge[Esize].u=i;
Edge[Esize].v=j;
Esize++;
}
}
}
printf("%.2lf\n",Bellman(,Psize));
}
return ;
}

poj 1556 The Doors的更多相关文章

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

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

  2. POJ 1556 The Doors 线段交 dijkstra

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

  3. POJ 1556 - The Doors - [平面几何+建图spfa最短路]

    题目链接:http://poj.org/problem?id=1556 Time Limit: 1000MS Memory Limit: 10000K Description You are to f ...

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

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

  5. poj 1556 The Doors(线段相交,最短路)

      The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7430   Accepted: 2915 Descr ...

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

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

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

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

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

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

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

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

随机推荐

  1. css固定div头部不随滚动条滚动

    给div加浮动: position:fixed; 固定宽度,高度,距离头部,左部为0:width: 99%; height: 80px; top:0; left: 0;

  2. loadrunner工具使用之脚本创建

    loadrunner工具使用之脚本创建 一.创建脚本 1.打开loadrunner,选择第一个控件VuGen(创建/编辑脚本),点击

  3. mysql 重复数据防止插入:)

    insert into table (id, name, age) values(1, "A", 19) on duplicate key update name=values(n ...

  4. javascript中document.appendChild和document.body.appendChild的问题

    在IE7中 var conentDiv = document.createElement("div"); document .body .appendChild(conentDiv ...

  5. java与微信企业号交互

    微信企业号接收消息(使用SpringMVC): http://blog.csdn.net/omsvip/article/details/39480577 微信企业号api: http://qydev. ...

  6. 使用虚拟机win7系统遇到问题及解决

    安装VMware并在其中安装win7专业版系统,这里不再赘述.因为...我就是照着百度来的.哈哈 说说使用中遇到的问题. 本来安装成功后,可以很愉快的运行着.后来莫名奇妙的出现了两个问题:1.虚拟机运 ...

  7. Keynote of Python III

    [Keynote of Python III] 1.许多大型网站是用Python开发的,例如YouTube.Instagram,还有国内的豆瓣.很多大公司,包括Google.Yahoo等,甚至NASA ...

  8. 在将 varchar 值 '1,2,3,4,5,6,7,8' 转换成数据类型 int 时失败。

    alter PROCEDURE PrTradingDelete ) AS BEGIN WHERE id in(@id) END GO 执行上面这个存储过程会异常.提示 :在将 varchar 值 '1 ...

  9. memcache与memcached介绍及安装配置

    也许大家一看到Memcache和Memcached会有点晕,这两者有什么关系又有什么区别呢,下面先给大家说下Memcached,Memcached是一个高性能的分布式内存对象缓存系统,用于动态Web应 ...

  10. C#中不同的线程对控件的更改

    .net 不允许跨线程个性其它线程创建的控件. 要想实现这个功能就需要用 InvokeRequired 检查是不是由该线程创建的控件,如果是直接操作,如果不是则 用Invoke 添加一个委托再加上参数 ...