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. 关于Eclipse中Jsp页面打不开并且显示Failed to create the part's controls的解决办法

    问题描述:同事从svn上导入的一个项目,jdk都设置好了以后,java.xml.html等文件都能打开,唯独jsp文件打不开,并且显示Failed to create the part's contr ...

  2. Java中的int和Integer

    代码: public class Test{ public static void main(String[] args){ Integer i01 = 59; int i02 = 59; Integ ...

  3. 给软件增加注册功能 c#

    1.软件注册类 using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...

  4. push方法的页面间跳转--

    一,自定义动画写push方法-- 添加coreGraphics.framework框架 在CATransitionAnimation.h文件里面引入-- #import <QuartzCore/ ...

  5. 【1】Laravel5.1 安装

    1.安装composer http://www.phpcomposer.com/ 这个是中文网址里边有教程,但是由于被墙的缘故,可以通过下边这个链接下载Windows安装包 http://docs.p ...

  6. POJ1636 动态规划+并查集

    POJ1636 问题重述: 两个监狱中各有m个囚犯,欲对这两个监狱中的囚犯进行等数量的交换.已知某些囚犯不能关押在同一个监狱,求解可以交换人数的最大值k (k < m/2). 分析: 假设监狱1 ...

  7. MongoDB备份数据库&导入数据库

    今天需要对线上的MongoDB中的webpage库进行备份,然后在本地导入备份的库. 1.备份整个MongoDB数据库 mongodump -h dbhost --port 端口 -u 用户名 -p ...

  8. Uubntu14.04 LST安装NodeJS

    1:从官网下载node.js源码http://nodejs.org/download/ 当前最新版为node-v0.10.33 2:安装 $ tar zxvf node-v0.10.33.tar.gz ...

  9. 关于Android界面编程与视图(View)组件

    UI组件--------------->android.widget.* View组件------------->android.view.* 视图(View)组件 所有UI组件都是建立在 ...

  10. GCD 倒计时

    今天在Code4App上看了一个GCD倒计时的Demo,觉得不错代码贴出来备用 -(void)startTime{ __block ; //倒计时时间 dispatch_queue_t queue = ...