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. js中完数的输出

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  2. QWidget使用qss样式的background-image属性

    最近在学习Qt使用QSS样式美化窗口部件的内容.发现在对QWidget应用background-image改变窗口背景图片时,QWidget的窗口背景并未生效.工程建立如下:    1.新建 Qt A ...

  3. Git / Bower Errors: Exit Code # 128 & Failed connect

    今天第一次使用bower来安装插件,上来就报了这个错. 然后在google上查找,很多人都有做出回答,让执行如下 git config --global url.https://github.com/ ...

  4. 关于Windows8.1更新后Sql Server服务消失的处理办法

    前言 微软在17日发布了windows8.1,兴致勃勃地花了半天的时间更新了,不过不知所云的是,在20日又被卸下Windows Store.此为背景. 影响 更新完毕做开发的时候,发现SqlServe ...

  5. 查看Linux系统相关版本信息

    1.“uname -a” 查看电脑以及操作系统的相关信息 2.“cat /proc/version” 查看运行的内核版本 3."cat /etc/redhat-release",  ...

  6. python文件批量改名

    python对文件进行批量改名用到的是os模块中的listdir方法和rename方法. os.listdir(dir)  :获取指定目录下的所有子目录和文件名 os.rename(原文件名,新文件名 ...

  7. [C入门 - 游戏编程系列] 环境篇

    这一系列笔记的代码都是在Ubuntu 14.04下编码并测试的,原因无他,因为我笔记本电脑只装了一个Ubuntu系统,其中唯一使用的第三方库SDL也是开源并且跨平台的.所以即使你用的是Windows或 ...

  8. mvc4 基于Area实现插件模块化开发

    对于一个较大规模的Web应用,可以从功能上通过Area将其划分为为较小的单元.每个Area相当于一个独立的子系统,具有一套包含Model.Views和Controller在内 的目录结构和配置文件.一 ...

  9. LeetCode_Distinct Subsequences

    Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...

  10. Qt如何去掉按钮等控件的虚线框(焦点框)(两种方法)

    方法1:可以通过代码ui->pushButton->setFocusPolicy(Qt::NoFocus)或在Qt Creator的属性列表中设置. 方法2:如果在嵌入式设备中需要通过按键 ...