链接

枚举两点 若不和任何线段相交 建边为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. 完整学习git三 查看暂存区目录树 git diff

    1显示暂存区中的目录树 git ls-files git ls-tree git diff 魔法 1工作区与暂存区比较 git diff 2工作区与HEAD比较 git diff HEAD 3暂存区与 ...

  2. VI 命令简介

    1.打开一个文件  vi 文件路径 2.命令模式转换  输入模式 i  命令模式  esc 3.复制 和 粘贴 1)将光标移动到将要复制的行处,按yy进行复制当前行(按nyy复制n行),再移动到粘贴位 ...

  3. awk用法小结(作者总结)

    http://www.chinaunix.net/old_jh/24/691456.html http://wenku.baidu.com/view/ebac4fc658f5f61fb736664d. ...

  4. masonry插件和infinitescroll插件实现无刷新无分页完美瀑布流

    地址有:http://www.17sucai.com/pins/2657.html 如果你善于发现美,如果你善于观察新鲜的事物,如果你是一名有爱的前端攻城师或设计尸,那么你一定不会对下面图片中的结构感 ...

  5. 检索 COM 类工厂中 CLSID 为 {} 的组件时失败,原因是出现以下错误: 80070005

    检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80070005.跟踪了一下,结果是将记录导出 ...

  6. 2015 AlBaath Collegiate Programming Contest A

    Description Tamer is traveling with his brother on a long highway. He sees a traffic light at a dist ...

  7. MVC 过滤器

  8. java课堂动手动脑博客

    随机生成10个数,填充一个数组,然后用消息框显示数组内容,接着计算数组元素的和,将结果也显示在消息框中. 要求将设计思路.程序流程图.源程序代码.结果截图.编程总结等发表到博客园. (截止时间2015 ...

  9. C#其他

    1.switch - if ...else if...switch(表达式) { case 值: ..... break; case 值: ..... break; default: ..... br ...

  10. js友好提示是否继续,post提交

    <script type="text/javascript"> function delcheck(qId,typeid) { if (!confirm('确定删除吗? ...