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. HDU 4859 海岸线(最小割+最大独立点权变形)

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题意: 欢迎来到珠海!由于土地资源越来越紧张,使得许多海滨城市都只能依靠填海来扩展市区以求发展.作为Z市的 ...

  2. Linux下清空或删除大文件内容的2种方法

    在Linux终端下处理文件时,有时候我们想要直接清空文件的内容时但又不用使用任何Linux命令行编辑器,去打开这些文件.那如何才能达到这个目的呢? 1.通过重定向到NULL来清空文件内容 清空或者让一 ...

  3. _spellmod_leech_spell

    comment  备注 spell 技能ID,玩家释放该技能时附带吸血效果 meetAura  产生吸血效果需要满足的光环ID,比如做一个空的光环,为寒冰箭吸血光环,则有些光环时候,寒冰箭会附带吸血效 ...

  4. 【bzoj】4538: [Hnoi2016]网络

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4538 维护一个数据结构支持对于一颗树的操作,需要支持: 1.对于树上的一条路径上的每个点上 ...

  5. Systemd初始化进程/RHEL 6系统中System V init命令与RHEL 7系统中systemctl命令的对比

    Linux操作系统的开机过程是这样的,即从BIOS开始,然后进入Boot Loader,再加载系统内核,然后内核进行初始化,最后启动初始化进程.初始化进程作为Linux系统的第一个进程,它需要完成Li ...

  6. nginx的使用教程

    一.基本概念 1.1 正向代理和反向代理 (参考文档:https://www.cnblogs.com/hafiz/p/7233306.html) 假设我们给定客户端A.代理服务器B.以及最终服务器C ...

  7. hibernate事务规范写法

    @Test public void testTx() { SessionFactory sessionFactory = null; Session session = null; Transacti ...

  8. 分组查询以及having使用

    Group  by 注意事项:对查询的列有限制,除了聚合函数外,就必须是分组的项 order  by总是放在最后 代码示例: select Gender as 性别 ,count (Gender) a ...

  9. mint fcitx搜狗输入法不显示输入框,其他输入法丢失皮肤

    mint18.3 因为这个原因刚刚重装过,结果一不留神又这样了. 这次原因相对清晰: 双屏显示下,合屏睡眠,打开之后,发现卡死了.屏幕分辨率改变了似的. 然后再重启,发现输入法悬浮框变大了,然后输入法 ...

  10. Python Selenium 文件下载

    Python Selenium 进UI自动化测试时都会遇到文件上传和下载的操作,下面介绍一下文件下载的操作 这里介绍使用FireFox浏览器进行文件下载的操作. 1.设置文件默认下载地址 如下图,fi ...