题目大意:有一个房间(左上角(0,10),右下角(10,0)),然后房间里有N面墙,每面墙上都有两个门,求出来从初始点(0,5),到达终点(10,5)的最短距离。

 
分析:很明显根据两点之间直线最短,所以所走的路线一定是点之间的连线,只需要判断一下这两点间知否有墙即可。
 
代码如下:
======================================================================================================================================
#include<math.h>
#include<algorithm>
#include<stdio.h>
using namespace std; const int MAXN = ;
const double oo = 1e9+;
const double EPS = 1e-; struct point
{
double x, y, len;
point(double x=, double y=, double len=):x(x),y(y),len(len){}
point operator - (const point &t) const{
return point(x-t.x, y-t.y);
}
int operator *(const point &t) const{
double c = x*t.y - y*t.x;
if(c > EPS)return ;
if(fabs(c)<EPS)return ;
return -;
}
};
struct Wall
{
point A, B;
Wall(point A=, point B=):A(A), B(B){}
}; bool CanLine(point a, point b, Wall w[], int N)
{
for(int i=; i<N; i++)
{
if( w[i].A.x < b.x || w[i].A.x > a.x )
continue;
int t = (a-b)*(w[i].A-b) + (a-b)*(w[i].B-b); if(t == )
return false;
} return true;
} int main()
{
int M; while(scanf("%d", &M) != EOF && M != -)
{
int i, j, nw=, np=;
double x, y[];
Wall w[MAXN]; point p[MAXN]; p[] = point(, , );
while(M--)
{
scanf("%lf%lf%lf%lf%lf", &x, &y[], &y[], &y[], &y[]); p[np++] = point(x, y[], oo), p[np++] = point(x, y[], oo);
p[np++] = point(x, y[], oo), p[np++] = point(x, y[], oo);
w[nw++] = Wall(point(x, -), point(x, y[]));
w[nw++] = Wall(point(x, y[]), point(x, y[]));
w[nw++] = Wall(point(x, y[]), point(x, ));
}
p[np++] = point(, , oo); for(i=; i<np; i++)
for(j=; j<i; j++)
{
point t = p[i] - p[j];
t.len = sqrt(t.x*t.x+t.y*t.y); if(p[i].len > t.len + p[j].len && CanLine(p[i], p[j], w, nw) == true)
p[i].len = t.len + p[j].len;
} printf("%.2f\n", p[np-].len);
} return ;
}

The Doors - POJ 1556 (线段相交)的更多相关文章

  1. poj 1066 线段相交

    链接:http://poj.org/problem?id=1066 Treasure Hunt Time Limit: 1000MS   Memory Limit: 10000K Total Subm ...

  2. poj 1269 线段相交/平行

    模板题 注意原题中说的线段其实要当成没有端点的直线.被坑了= = #include <cmath> #include <cstdio> #include <iostrea ...

  3. poj 2653 线段相交

    题意:一堆线段依次放在桌子上,上面的线段会压住下面的线段,求找出没被压住的线段. sol:从下向上找,如果发现上面的线段与下面的相交,说明被压住了.break掉 其实这是个n^2的算法,但是题目已经说 ...

  4. poj 2653 线段相交裸题(解题报告)

    #include<stdio.h> #include<math.h> const double eps=1e-8; int n; int cmp(double x) { if( ...

  5. poj 1410 线段相交判断

    http://poj.org/problem?id=1410 Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  6. Pipe - POJ 1039(线段相交交点)

    题目大意:有一个不反光并且不透光的管道,现在有一束光线从最左端进入,问能达到的最右端是多少,输出x坐标.   分析:刚开始做是直接枚举两个点然后和管道进行相交查询,不过这样做需要考虑的太多,细节不容易 ...

  7. Pick-up sticks - POJ 2653 (线段相交)

    题目大意:有一个木棒,按照顺序摆放,求出去上面没有被别的木棍压着的木棍.....   分析:可以维护一个队列,如果木棍没有被压着就入队列,如果判断被压着,就让那个压着的出队列,最后把这个木棍放进队列, ...

  8. POJ 2074 | 线段相交

    #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #defi ...

  9. POJ 1556 The Doors 线段交 dijkstra

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

随机推荐

  1. ZOJ 1076 Gene Assembly(LIS+路径打印 贪心)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=76 题目大意:在一个DNA上,给定许多基因的起始位置和结束位置,求出这 ...

  2. 跟我玩ADB——初识ADB

    ADB全称Android Debug Bridge, 是Android SDK的一个可以真实操作手机设备里面内容的工具. 一.功能介绍: 进入设备的shell进行命令行操作 使用5037端口,对设备进 ...

  3. U盘安装ubuntu时出现的gfxboot.c32:not a COM32R image问题

    方法特别简单:只需在提示后面输入   live  然后回车 就OK了

  4. php利用时间生成随机函数

    date("YmdHis",time()); rand();    生成随机数   当括号内无参数时 系统会以当前时间为种子进行随机数的生成 rand(1,10);  括号里面是生 ...

  5. jquery前端性能优化(持续添加。。。)

    1.选择器的使用 (1)$('#id')   使用id来定位dom元素是性能最高的方法.jQuery底层将直接调用本地方法document.getElementById().如果id直接可以找到所要对 ...

  6. Newtonsoft.Json工具类

    这个类用于序列化和反序列化类. 效果是当前最好的.微软都推荐使用.在建立MVC的里面已经引用了这个dll. 上面一篇文章要用到 SerializeHelper工具类 public class Seri ...

  7. shell抓取

    #!/bin/sh ` configDir="$dir/config" ipport="$configDir/ip_port" url="http:/ ...

  8. Chrome控制台

    先的简单介绍一下chrome的控制台,打开chrome浏览器,按f12就可以轻松的打开控制台 大家可以看到控制台里面有一首诗还有其它信息,如果想清空控制台,可以点击左上角那个来清空,当然也可以通过在控 ...

  9. 区分html与css中的属性

    CSS中id与Class的区别 1.在CSS文件里书写时,ID加前缀"#":CLASS用"." 2.id一个页面只可以使用一次:class可以多次引用. 3.I ...

  10. 高性能页面加载技术(流水线加载)BigPipe的C#简单实现(附源码)

    一,BigPipe简介 BigPipe是一个重新设计的基础动态网页服务体系.大体思路是,分解网页成叫做Pagelets的小块,然后通过Web服务器和浏览器建立管道并管理他们在不同阶段的运行.这是类似于 ...