链接

枚举两点 若不和任何线段相交 建边为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. APP运营推广那点事【干货】

    你的手机里面有多少应用?什么样的手机应用吸引你?下载之后经常用还是让他shi在那里?又或者刚点进去就卸载? 一款成功的应用,开发APP只是第一步,比前者更重要的是“养”APP,APP就像是一个需要不断 ...

  2. expect语法

    沙河西ftp上传,使用了expect语言的脚本. 我们经常会遇到一些需要与服务器程序打交道的场景,比如,从登陆某个服务器,然后进行某项工作.这很平常,但是如果把这个工作自动化进行,你就需要一个程序能自 ...

  3. CSS3前缀自动补全方案和插件

    第一种方法:prefix free,js插件,大小2kb,直接导入,无需任何浏览器兼容前缀 <script src="prefixfree.min.js"></s ...

  4. MyEclipse+Android 安装配置

    1.先安装M有Eclipse    就是不断点:下一步下一步最后finish  激活:http://blog.my-eclipse.cn/myeclipse-2014-crack.html (该网站上 ...

  5. hack是什么

    不同浏览器对css的解析是不同是,因此需要css hack来解决浏览器局部的兼容性问题.针对不同浏览器写不同的CSS代码的过程叫CSS  Hack. 常见的hack有三种形式,分别是CSS属性hack ...

  6. 每日一九度之 题目1030:毕业bg

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2046 解决:894 题目描述:     每年毕业的季节都会有大量毕业生发起狂欢,好朋友们相约吃散伙饭,网络上称为“bg”.参加不同团体的b ...

  7. String类方法

    1.charAt(int index)  返回指定索引处的 char 值. 2. length() 返回此字符串的长度. 3.String replace(char oldChar, char new ...

  8. cookie存储记录

    ////// 历史记录 $(function () { // 标题 var art_title = $("#Lbl_Hotel_Name").text(); // 得到当前路径 v ...

  9. THE DRUNK JAILER 分类: POJ 2015-06-10 14:50 13人阅读 评论(0) 收藏

    THE DRUNK JAILER Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24918   Accepted: 1563 ...

  10. 使用Jvisualvm监控JVM的内存、CPU、线程

    最近做性能测试发现很多性能问题,面对一些开发小白的数据结构思想,真想喊一声:放开那个代码,让我来!冲动. 面对WEB站点开发,性能测试是经常要做的,下面一种介绍如何结合性能测试工具,更好的监控WEB服 ...