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 ;
}

最新文章

  1. Linux命令全称
  2. POJ 1509 最小表示法
  3. Linux 概念架构的理解
  4. ASP.NET MVC:窗体身份验证及角色权限管理示例
  5. ThinkPHP之APP_DEBUG给我带来的问题
  6. c#扩展方法的理解(一:初识)
  7. oracle字符集问题总结
  8. Spark on YARN的两种运行模式
  9. zju2676 Network Wars 分数规划+网络流
  10. win7 安装 sql2000
  11. BZOJ-2150部落战争(最小路径覆盖)
  12. npm -v;报错 cannot find module &quot;wrapp&quot;
  13. C# 控件消失等问题
  14. RSA签名验证
  15. C#基础知识回顾-- 反射(2)
  16. B-Tree外存数据结构 _(B 树)第二部分
  17. [Spark][Python]DataFrame select 操作例子
  18. nmon+nmon analyser安装使用教程
  19. 【面试题】100IT名企java面试必考面试题
  20. C#在splitContainer1控件和panel控件中显示窗体

热门文章

  1. dedecms代码研究七
  2. GPUImage相关(转)
  3. 关于yaha中文分词(将中文分词后,结合TfidfVectorizer变成向量)
  4. FizzlerEx —— 另一个HtmlAgilityPack的CSS选择器扩展,
  5. Reactjs 入门基础(一)
  6. Linux(centos)系统各个目录的作用详解
  7. Error -27780: [GENERAL_MSG_CAT_SSL_ERROR]connect to host &quot;124.202.213.70&quot; failed: [10054] Connection reset by peer [MsgId: MERR-27780]
  8. java基础十一[远程部署的RMI](阅读Head First Java记录)
  9. 客户端连接linux经常间隔性断开链接
  10. 第1章 C#类型基础