链接

枚举两点 若不和任何线段相交 建边为dis(i,j) floyd求最短路

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
double x,y;
point(double x=,double y=):x(x),y(y){}
}p[N];
struct line
{
point u,v;
}li[N];
double w[N][N];
typedef point pointt;
pointt operator - (point a,point b)
{
return pointt(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
}
double dis(point a)
{
return sqrt(a.x*a.x+a.y*a.y);
}
double cross(point a,point b)
{
return a.x*b.y-a.y*b.x;
}
bool segprointer(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 dcmp(c1)*dcmp(c2)<&&dcmp(c3)*dcmp(c4)<;
}
int main()
{
int n,i,j,k;
while(scanf("%d",&n)!=EOF)
{
if(n==-) break;
int g = ;
for(i = ; i <= ; i++)
{
for(j = ; j<= ; j++)
w[i][j] = INF;
w[i][i] = ;
}
int o = ;
for(i = ; i <= n ;i++)
{
double k;
scanf("%lf",&k);
for(j = ; j <= ; j++)
{
p[++g].x = k;
scanf("%lf",&p[g].y);
}
point pp = point(k,);
li[++o].u = pp;
li[o].v = p[g-];
li[++o].u = p[g-];
li[o].v = p[g-];
li[++o].u = p[g];
pp = point(k,);
li[o].v = pp;
}
p[g+] = point(,);
p[g+] = point(,);
//printf("%d\n",segprointer(p[g+1],p[g+2],li[5].u,li[5].v));
for(i = ; i <= g+; i++)
for(j = i+; j <= g+; j++)
{
if(i==j) continue;
for(k = ; k <= o ; k++)
{
if(segprointer(p[i],p[j],li[k].u,li[k].v))break; }
if(k>o)
w[i][j] = w[j][i] = dis(p[i]-p[j]);
//printf("%.2f %.2f %.2f %.2f %.2f\n",p[i].x,p[i].y,p[j].x,p[j].y,w[i][j]);
}
for(i = ; i <= g+ ; i++)
for(j = ; j <=g+ ;j++)
for(k = ; k <= g+ ; k++)
w[j][k] = min(w[j][i]+w[i][k],w[j][k]);
printf("%.2f\n",w[g+][g+]);
}
return ;
}

poj1556The Doors的更多相关文章

  1. ACM/ICPC 之 最短路径-Bellman Ford范例(POJ1556-POJ2240)

    两道Bellman Ford解最短路的范例,Bellman Ford只是一种最短路的方法,两道都可以用dijkstra, SPFA做. Bellman Ford解法是将每条边遍历一次,遍历一次所有边可 ...

  2. poj 1556 The Doors

    The Doors Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u   Java ...

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

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

  4. 100 doors

    Question There are 100 doors in a row that are all initially closed. You make 100 passes by the door ...

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

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

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

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

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

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

  8. POJThe Doors AND NYIST 有趣的问题

    POJThe Doors AND NYIST 有趣的问题 题目链接:pid=227" target="_blank">Click Here~ 题目分析: 给你横纵坐 ...

  9. 【DOORS】如何基于DOORS实施需求管理

    引言 IBM Rational DOORS,简称DOORS,是被业界广泛认可的需求管理工具,在国内外需求管理领域具有较高的市场占有率.需求管理作为传统的工程领域,理论发展相对成熟和健全.随着越来越多的 ...

随机推荐

  1. ecshop后台通过ajax搜索原理

    ecshop的搜索其实是功能十分强大的,但是ecshop搜索功能前台和后台还不大一样,前台主要是通过get方式,提交的url进行分页,而在ecshop的后台,则是接受表单的搜索条件,然后通过js发布到 ...

  2. oracle数据库表空间文件收缩实例

    Oracle数据文件收缩实例 数据文件的作用 HWM的基本概念 查看数据文件的使用情况 包括内容:数据文件大小,已经used空间,free空间,hwm信息 select /*+ ordered use ...

  3. git 本地分支与远程分支关联的一种方法

    github上已经有master分支 和dev分支 在本地 git checkout -b dev 新建并切换到本地dev分支 git pull origin dev 本地分支与远程分支相关联 在本地 ...

  4. Android动画的使用总结

    1.补间动画(透明渐变.平移.旋转.缩放.组合) 方法一:通过xml文件设置 1-1:创建:res/anim 1-2:java代码写调用 Animation a = AnimationUtils.lo ...

  5. 20151221001 GridView 模板

    <asp:GridView ID="GridView1"                 runat="server" AllowPaging=" ...

  6. LA 4064 Magnetic Train Tracks

    题意:给定平面上$n(3\leq n \leq 1200)$个无三点共线的点,问这些点组成了多少个锐角三角形. 分析:显然任意三点可构成三角形,而锐角三角形不如直角或钝角三角形容易计数,因为后者有且仅 ...

  7. phpcms 04

    首页index.html 首页头条推荐 <div class="col-left"> <div class="news-hot"> &l ...

  8. DLL数据共享在不同处定义效果不同..

    DLL头文件: #ifndef _DLL_SAMPLE_H #define _DLL_SAMPLE_H #pragma data_seg("ShareReadAndWrite") ...

  9. 四个好看的CSS样式表格

    文章来源 http://www.cnphp6.com/archives/58020 1. 单像素边框CSS表格 这是一个非经常常使用的表格样式. 源码: 2. 带背景图的CSS样式表格 和上面差点儿相 ...

  10. 【Thread】多线程的异常处理?

    线程中处理异常是个头疼的问题,在异步的代码中,如何将异常捕获. 捕获异常后,将异常反馈给开发者,或用户.一般来说,反馈给开发者,多数方式在是日志中打印异常日志:而反馈给用户,多数是在界面上友好提示(比 ...