The Doors

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

题目就是说,给你一个10*10的正方形房间,里面会用一些垂直与x轴的墙隔开.每个墙上有两个门,然后给你门的两个端点坐标,要求求出从(0,5)走到(10,5)的最短路;

那其实本质上就是最短路,如果没有墙隔开,就单单这几个点,那就很水了.现在还要求判断一下,某两点之间是否可以直达.所谓直达,就是,这两点的连线不与其他任何墙相交(交于端点是允许的).

至此,题目解完了.

 #include<cstdio>
 #include<cstring>
 #include<algorithm>
 #include<iostream>
 #include<cmath>
 #define INF 10000000
 using namespace std;
 ;
 int n;
 ][];
 ];
 ],o;
 double dis(point a,point b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
 :x>eps;}
 double cross(point a,point b){return a.x*b.y-a.y*b.x;}
 point operator - (point a,point b){point ret; ret.x=a.x-b.x,ret.y=a.y-b.y; return ret;}
 int Intersect(point a,point b,point c,point d){
     double s1,s2,s3,s4;
     int d1,d2,d3,d4;
     d1=dcmp(s1=cross(a-c,b-c));
     d2=dcmp(s2=cross(a-d,b-d));
     d3=dcmp(s3=cross(c-a,d-a));
     d4=dcmp(s4=cross(c-b,d-b));
     &&(d3^d4)==-) ;
     ;
 }
 int main(){
     ; scanf("%d",&n)){
         ,cnt0=; P[].x=,P[].y=;
         ; i<n; i++){
             double x,y1,y2,y3,y4;
             scanf("%lf%lf%lf%lf%lf",&x,&y1,&y2,&y3,&y4);
             P[cnt].x=x,P[cnt++].y=y1;
             P[cnt].x=x,P[cnt++].y=y2;
             P[cnt].x=x,P[cnt++].y=y3;
             P[cnt].x=x,P[cnt++].y=y4;
             seg[cnt0].a.x=x,seg[cnt0].a.y=,seg[cnt0].b.x=x,seg[cnt0++].b.y=y1;
             seg[cnt0].a.x=x,seg[cnt0].a.y=y2,seg[cnt0].b.x=x,seg[cnt0++].b.y=y3;
             seg[cnt0].a.x=x,seg[cnt0].a.y=y4,seg[cnt0].b.x=x;seg[cnt0++].b.y=;
         }
         P[cnt].x=,P[cnt].y=;
         ; i<=cnt; i++){
             ; j<=cnt; j++) cost[i][j]=INF; cost[i][i]=;
         }
         ; i<=cnt; i++){
             ; j<=cnt; j++) if (j!=i){
                 o.a.x=P[i].x,o.a.y=P[i].y,o.b.x=P[j].x,o.b.y=P[j].y;
                 ;
                 ; k<cnt0; k++) ){flag=; break;}
                 ) cost[i][j]=dis(P[i],P[j]);
             }
         }
         ; k<=cnt; k++)
             ; i<=cnt; i++)
                 ; j<=cnt; j++) if (cost[i][k]+cost[k][j]<cost[i][j]) cost[i][j]=cost[i][k]+cost[k][j];
         printf(][cnt]);
     }
     ;
 }

The Doors的更多相关文章

  1. poj 1556 The Doors

    The Doors Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u   Java ...

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

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

  3. 100 doors

    Question There are 100 doors in a row that are all initially closed. You make 100 passes by the door ...

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

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

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

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

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

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

  7. POJThe Doors AND NYIST 有趣的问题

    POJThe Doors AND NYIST 有趣的问题 题目链接:pid=227" target="_blank">Click Here~ 题目分析: 给你横纵坐 ...

  8. 【DOORS】如何基于DOORS实施需求管理

    引言 IBM Rational DOORS,简称DOORS,是被业界广泛认可的需求管理工具,在国内外需求管理领域具有较高的市场占有率.需求管理作为传统的工程领域,理论发展相对成熟和健全.随着越来越多的 ...

  9. POJ1556 The Doors [线段相交 DP]

    The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8334   Accepted: 3218 Descrip ...

  10. CodeForces 1143A The Doors

    The Doors 签到题 #include <iostream> using namespace std; int a[200005]; int main() { int n; scan ...

随机推荐

  1. 3、Python迭代器、列表解析及生成器(0530)

    1.动态语言 sys.getrefcount()    //查看对象的引用计数 增加对象的引用计数场景 对象创建时:以赋值的方式,创建变量名的同时就会创建变量 将对象添加进容器时:类似list.app ...

  2. Linux命令之nl命令

    nl 命令在 Linux 系统中用来计算文件中行号.nl 可以将输出的文件内容自动的加上行号,其默认的结果和 与 cat -n 有点不太一样,nl 可以将行号做比较多的显示设计,包括位数是否自动补齐 ...

  3. 使用R语言的RTCGA包获取TCGA数据--转载

    转载生信技能树 https://mp.weixin.qq.com/s/JB_329LCWqo5dY6MLawfEA TCGA数据源 - R包RTCGA的简单介绍 - 首先安装及加载包 - 指定任意基因 ...

  4. 【Java】【事件处理机制】

    import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.Actio ...

  5. android studio 的基本使用和建立一个小项目

    https://github.com/allenxieyusheng/Android-Studio

  6. CSS垂直居中查询宝典

    一.垂直居中的用处 设计稿需求 当我们抱怨设计反复不定的时候,试着理解一下.每一位开发者也会是一位用户,请多多用'用户'的角色去开发.就比如下面这图,你会更稀饭哪种格式呢? 如果我们使用一个webap ...

  7. 蚂蚁金服×西安银行 | 西安银行手机银行App的智能升级之路

    小蚂蚁说: 当前,数字化信号已经逐渐深入到社会的每个角落,影响着用户的心智和行为,来到数字化时代门口的银行,需要注意到数字化信号.西安银行通过引入蚂蚁金服移动开发平台mPaaS,对手机银行进行架构升级 ...

  8. Servlet快速入门

    servlet是运行在服务端的java小程序,用来处理客户端请求,响应给浏览器的动态资源 servlet规范:包含3个技术点 1.servlet技术 2.filter技术 3.listener技术 s ...

  9. 使用openpyxl的styles,实现写入值时加背景色

    所用文件.数据和上一节代码中用的一致 本次直接贴代码 from openpyxl.styles import fills from openpyxl import load_workbook clas ...

  10. Qt5文件操作_保存成"UTF-8"格式

    1. bool TdrawSvg::Save2File(char* _pcFullFileName) { // http://blog.csdn.net/u011314012/article/deta ...