POJ 1556 - The Doors
题意:
    在 10x10 的空间里有很多垂直的墙,不能穿墙,问你从(0,5) 到 (10,5)的最短距离是多少.
    
分析:
    
    要么直达,要么一定是墙的边缘点之间以及起始点、终点的连线.
    
    所以先枚举墙上每一点到其他点的直线可达距离,就是要判定该线段是否与墙相交(不含端点).
    
    然后最短路.

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
const double INF = 1e10;
const double eps = 1e-;
int dcmp(double x)
{
return fabs(x) < eps ? : (x < ? - : );
}
struct Point
{
double x,y;
Point(double x1 = ,double y1 = ) : x(x1), y(y1) {}
};
Point operator - (Point a,Point b)
{
return Point(a.x - b.x, a.y - b.y);
}
double Det(Point a,Point b)
{
return a.x * b.y - a.y * b.x;
}
double Dot(Point a,Point b)
{
return a.x * b.x + a.y * b.y;
}
double Length(Point a)
{
return sqrt(Dot(a, a));
}
bool OnSegment(Point p, Point a1, Point a2)
{
return dcmp(Det(a1 - p, a2 - p)) == && dcmp(Dot(a1 - p, a2 - p) ) <= ;
}
struct Line
{
Point s,e;
Line() {}
Line(Point s1, Point e1) : s(s1), e(e1) {}
};
bool SegCross(Point a1, Point a2, Point b1, Point b2)
{
double c1 = Det(a2 - a1, b1 - a1);
double c2 = Det(a2 - a1, b2 - a1);
double c3 = Det(b2 - b1, a1 - b1);
double c4 = Det(b2 - b1, a2 - b1);
if(dcmp(c1) * dcmp(c2) < && dcmp(c3) * dcmp(c4) < ) return ;
else return ;
} int n;
Line l[];
Point p[];
double map[][];
int main()
{
while (~scanf("%d", &n) && n != -)
{
p[] = Point(, );
p[] = Point(, );
int t = , m = ;
for (int i = ; i <= n; i++)
{
double x; Point p1,p2,p3,p4;
scanf("%lf%lf%lf%lf%lf",&x, &p1.y, &p2.y, &p3.y, &p4.y);
p1.x = p2.x = p3.x = p4.x = x;
l[m++] = Line(Point(x,),p1);
l[m++] = Line(p2, p3);
l[m++] = Line(p4, Point(x,));
p[t++] = p1; p[t++] = p2; p[t++] = p3; p[t++] = p4;
}
for (int i = ; i < t; i++)
for (int j = ; j < t; j++)
map[i][j] = INF;
for (int i = ; i < t; i++)
{
for (int j = i+; j < t; j++)
{
if (p[i].x == p[j].x) continue;
bool flag = ;
for (int k = ; k < m; k++)//枚举墙
{
if(SegCross(p[i], p[j], l[k].e, l[k].s))
{
flag = ; break;
}
}
if (flag)
{
map[i][j] = map[j][i] = Length(p[i]-p[j]);
} }
}
for(int i = ; i < t; i++) map[i][i] = ;
for (int k = ; k < t; k++)
for (int i = ; i < t;i++)
for (int j = ; j < t; j++)
map[i][j] = min(map[i][j], map[i][k] + map[k][j]);
printf("%.2f\n",map[][]);
}
}

POJ 1556 - The Doors 线段相交不含端点的更多相关文章

  1. POJ 1556 The Doors 线段交 dijkstra

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

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

    #include <iostream> #include <stdio.h> #include <string.h> #include <algorithm& ...

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

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

  4. POJ 1556 计算几何 判断线段相交 最短路

    题意: 在一个左下角坐标为(0,0),右上角坐标为(10,10)的矩形内,起点为(0,5),终点为(10,5),中间会有许多扇垂直于x轴的门,求从起点到终点在能走的情况下的最短距离. 分析: 既然是求 ...

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

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

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

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

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

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

  8. POJ 1066 Treasure Hunt(线段相交判断)

    Treasure Hunt Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4797   Accepted: 1998 Des ...

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

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

随机推荐

  1. 8 fastJson的使用

    Fastjson介绍 Fastjson是一个Java语言编写的JSON处理器,由阿里巴巴公司开发. 1.遵循http://json.org标准,为其官方网站收录的参考实现之一. 2.功能qiang打, ...

  2. hdu 1258 DFS

    I - 深搜 基础 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:10000KB     64bi ...

  3. python产生随机名字

    用到random.choice(序列) 在一个序列中随机选取一个值 import random as r a1=['张','金','李','王','赵'] a2=['玉','明','龙','芳','军 ...

  4. Nlog从下载到使用例子

    第一.首先下载nlog.dll 下载地址:http://pan.baidu.com/s/1i3DQsV7 第二.添加nlog.ll的引用 第三.代码 private static Logger log ...

  5. LODS LODSB LODSW LODSD 例子【载入串指令】

    http://qwop.iteye.com/blog/1958761 // lodsb.cpp : Defines the entry point for the console applicatio ...

  6. C51函数的递归调用

    前几天在写C51程序时用到了递归,简单程序如下: void WRITE_ADD(uchar addr,uchar wbyte) { START(); //先发送起始信号 WRITE_BYTE(0xa0 ...

  7. Eclipse配置JDK的源代码的src.zip

    Eclipse配置JDK的源代码的src.zip包很简单.只需要简单的几个步骤. 1.点 “window”-> “Preferences” -> “Java” -> “Install ...

  8. DELL WIN7系统安装 U盘

    1.老毛挑制作U盘启动安装  http://www.laomaotao.net/ 2.下载WIN7 COPY里面的内容到U盘根目录,然后将bootmgr文件更名为win7mgr 3.开进F2修改BIO ...

  9. Palindrome Partitioning 解答

    Question Given a string s, partition s such that every substring of the partition is a palindrome. R ...

  10. Python 入门教程 9 ---- A Day at the Supermarket

    第一节 1 介绍了for循环的用法 for variable in values: statement 2 for循环打印出列表的每一项 for item in [1 , 2 , 3]: print ...