这题就是,处理出没两个点。假设能够到达,就连一条边,推断可不能够到达,利用线段相交去推断就可以。最后求个最短路就可以

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std; #include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; struct Point {
double x, y;
Point() {}
Point(double x, double y) {
this->x = x;
this->y = y;
}
void read() {
scanf("%lf%lf", &x, &y);
}
}; typedef Point Vector; Vector operator - (Vector A, Vector B) {
return Vector(A.x - B.x, A.y - B.y);
} const double eps = 1e-8; int dcmp(double x) {
if (fabs(x) < eps) return 0;
else return x < 0 ? -1 : 1;
} double Cross(Vector A, Vector B) {return A.x * B.y - A.y * B.x;} //叉积 //能够不规范相交
bool SegmentProperIntersection2(Point a1, Point a2, Point b1, Point b2) {
double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1),
c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1);
return max(a1.x, a2.x) >= min(b1.x, b2.x) &&
max(b1.x, b2.x) >= min(a1.x, a2.x) &&
max(a1.y, a2.y) >= min(b1.y, b2.y) &&
max(b1.y, b2.y) >= min(a1.y, a2.y) &&
dcmp(c1) * dcmp(c2) <= 0 && dcmp(c3) * dcmp(c4) <= 0;
} const int N = 25; int n; struct Ban {
Point p[4];
void read() {
double a, y[4];
scanf("%lf", &a);
for (int i = 0; i < 4; i++) {
scanf("%lf", &y[i]);
p[i] = Point(a, y[i]);
}
}
} b[N]; struct Edge {
int u, v;
double w;
Edge(){}
Edge(int u, int v, double w) {
this->u = u;
this->v = v;
this->w = w;
}
}; vector<Edge> g[N * 4]; double dist(Point a, Point b) {
double dx = a.x - b.x;
double dy = a.y - b.y;
return sqrt(dx * dx + dy * dy);
} void add_edge(int u, int v, double d) {
g[u].push_back(Edge(u, v, d));
g[v].push_back(Edge(v, u, d));
} bool judge(int l, int r, Point aa, Point bb) {
for (int i = l; i <= r; i++) {
if (!SegmentProperIntersection2(aa, bb, b[i].p[0], b[i].p[1]) && !SegmentProperIntersection2(aa, bb, b[i].p[2], b[i].p[3]))
return false;
}
return true;
} double d[N * 4];
int vis[N * 4]; double spfa(int s, int t) {
memset(vis, 0, sizeof(vis));
queue<int> Q;
for (int i = 0; i <= t; i++) d[i] = 1e20;
d[0] = 0;
vis[0] = 1;
Q.push(0);
while (!Q.empty()) {
int u = Q.front();
Q.pop();
vis[u] = 0;
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i].v;
double w = g[u][i].w;
if (d[u] + w < d[v]) {
d[v] = d[u] + w;
if (!vis[v]) {
vis[v] = 1;
Q.push(v);
}
}
}
}
return d[t];
} int main() {
while (~scanf("%d", &n) && n != -1) {
for (int i = 0; i <= n * 4 + 1; i++) g[i].clear();
for (int i = 0; i < n; i++)
b[i].read();
if (judge(0, n - 1, Point(0, 5), Point(10, 5)))
add_edge(0, n * 4 + 1, 10);
for (int i = 0; i < n; i++) {
for (int j = 0; j < 4; j++) {
if (judge(0, i - 1, Point(0, 5), b[i].p[j]))
add_edge(0, i * 4 + j + 1, dist(Point(0, 5), b[i].p[j]));
if (judge(i + 1, n - 1, b[i].p[j], Point(10, 5)))
add_edge(n * 4 + 1, i * 4 + j + 1, dist(Point(10, 5), b[i].p[j]));
for (int k = i + 1; k < n; k++) {
for (int x = 0; x < 4; x++) {
if (judge(i + 1, k - 1, b[i].p[j], b[k].p[x]))
add_edge(i * 4 + j + 1, k * 4 + x + 1, dist(b[i].p[j], b[k].p[x]));
}
}
}
}
printf("%.2f\n", spfa(0, n * 4 + 1));
}
return 0;
}

POJ 1556 The Doors(计算几何+最短路)的更多相关文章

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

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

  2. POJ 1556 - The Doors 线段相交不含端点

    POJ 1556 - The Doors题意:    在 10x10 的空间里有很多垂直的墙,不能穿墙,问你从(0,5) 到 (10,5)的最短距离是多少.    分析:        要么直达,要么 ...

  3. POJ 1556 The Doors 线段交 dijkstra

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

  4. ●POJ 1556 The Doors(简单计算几何+最短路)

    ●赘述题目 10*10的房间内,有竖着的一些墙(不超过18个).问从点(0,5)到(10,5)的最短路. 按照输入样例,输入的连续5个数,x,y1,y2,y3,y4,表示(x,0--y1),(x,y2 ...

  5. POJ 1556 - The Doors - [平面几何+建图spfa最短路]

    题目链接:http://poj.org/problem?id=1556 Time Limit: 1000MS Memory Limit: 10000K Description You are to f ...

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

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

  7. poj 1556 The Doors(线段相交,最短路)

      The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7430   Accepted: 2915 Descr ...

  8. POJ 1556 The Doors --几何,最短路

    题意: 给一个正方形,从左边界的中点走到右边界的中点,中间有一些墙,问最短的距离是多少. 解法: 将起点,终点和所有墙的接触到空地的点存下来,然后两两之间如果没有线段(墙)阻隔,就建边,最后跑一个最短 ...

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

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

随机推荐

  1. jquery学习(2)--选择器

    jquery-李炎恢学习视频学习笔记.自己手写. 简单的选择器    css 写 法: #box{ color:#f00;}    //id选择器    jquery获取:$('#box').css( ...

  2. vb 添加状态栏

    1.新建一工程2.添加"部件" ms windows common controls 6.03.将StatusBar控件加至窗体中4.右键点击该控件,选"属性" ...

  3. Cocos2d-x 学习之路------(CCCallfunc 系列)

    CCCallFunc,CCCallFuncN,CCCallFuncND,CCCallFuncO类都是调用函数来执行动作,他们的使用只是局限于他们调用的的函数的参数不同而不同 CCCallFunc的回调 ...

  4. asp.net core + angular2

    asp.net core + angular2 的环境配置 国内整个对 asp.net core  和 angular2这些新出来的关注度不是太好.跟国外比很大差距. 我在试着去做这个整合的时候也碰到 ...

  5. 占成本85% SSD深度选购教你如何看颗粒

    颗粒是固态硬盘负责容量和传输的介质,在这一方面上与优盘产品是相同的,从外观上看,颗粒占据了整个固态硬盘内部70%左右的空间,其同样做为成本技术,根据厂商的用料不同,成为了固态硬盘内部核心材料. 颗粒的 ...

  6. ARM Cortex M3(V7-M架构)硬件启动程序 一

    Cortex-m3启动代码分析笔记 启动代码文件名是STM32F10X.S,它的作用先总结下,然后再分析. 启动代码作用一般是: 1)堆和栈的初始化: 2)中断向量表定义: 3)地址重映射及中断向量表 ...

  7. 在windows下进行linux开发:利用Vagrant+virtualbox(ShowDoc与mp3dish的作者)

    1,介绍Vagrant 我们做web开发的时候经常要安装各种本地测试环境,比如apache,php,mysql,redis等等.出于个人使用习惯,可能我们还是比较习惯用windows.虽然说在wind ...

  8. js 事件之 createEvent、dispatchEvent

    //document上绑定自定义事件ondataavailable document.addEventListener('customevent', function(event) { alert(e ...

  9. 04737_C++程序设计_第7章_类模板与向量

    例7.1 使用类模板的实例. 例7.2 求4个数中最大值的类模板程序. #include <iostream> using namespace std; template <clas ...

  10. Rikka with Chess(规律)

    Rikka with Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...