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. poj2456 二分逼近寻找正确答案

    Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10078   Accepted: 4988 ...

  2. Mysql学习(慕课学习笔记2)数据库的创建与删除

    创建数据库 { } 必选  | 从前后做选择   [ ] 可选 Create {database | schema} [if not exists] db_name [default] charact ...

  3. python学习第二天 --变量及其字符串

    python变量: 在计算机程序中,变量不仅可以是数字,还可以是任意数据类型. 在Python程序中,变量是用一个变量名表示,变量名必须是大小写英文.数字和下划线(_)的组合,且不能用数字开头. 在P ...

  4. Eclipse开发Python项目

    最近倒腾python自带的开发工具idle,用的很不习惯,还是用Eclipse编写python项目方便(自动补齐,智能报错,调试方便),下面就说说怎么用Eclipse编写python代码吧~ 1.安装 ...

  5. 单片微机原理P3:80C51外部拓展系统

    外部拓展其实是个相对来说很好玩的章节,可以真正开始用单片机写程序了,比较重要的是外部存储器拓展,81C55拓展,矩阵键盘,动态显示,DAC和ADC.   0. IO接口电路概念与存储器拓展 1. 为什 ...

  6. C语言实现OOP 版本3 :简化代码

    我倒是不追求代码和C++相似,但是应该追求简洁的代码,下面是一个新的尝试 shape.h #ifndef SHAPE_H #define SHAPE_H typedef struct shape_t ...

  7. vc获取时间戳

    CTime cTime = CTime::GetCurrentTime(); CString msg; msg.Format("%u",cTime .GetTime()); Afx ...

  8. Java获取当前日期的前一个月,前一天的时间

    Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -); //得到前一天 calendar.add(Cal ...

  9. MySQL强制性操作

    1.强制索引FORCE INDEX SELECT * FROM TABLE1 FORCE INDEX (FIELD1) … 只使用建立在FIELD1上的索引,而不使用其它字段上的索引. 2.忽略索引 ...

  10. linux网址

    1. 上海爱墨电子科技有限公司 http://www.shaimo.cn/showproduct.asp?piccat_id=196&pic_id=780 2. http://lxr.free ...