链接

枚举两点 若不和任何线段相交 建边为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. ectouch第四讲 之缓存文件的生成

    当第一次访问\mobile主页的时候,就会生成如下缓存文件:缓存文件存放在\mobile\data\cache\文件夹下 |-mobile |-data |-cache |-compiled [前台编 ...

  2. PHP上传文件详解 错误提示

    首先在php.ini里配置上载文件.有以下几个重要的配置单: 选项 默认值 说明 post_max_size 8M 控制以后的POST请求的最大规模.必须大于upload_max_filesize选项 ...

  3. dedecms的title怎么优化?

    (1)首页:index.htm 模板:<title>k1,k2,k3 {dede:global.cfg_webname/}</title> 规则:3个关键词+网站名称 示例:& ...

  4. C++的几种强制类型转换

    有时我们希望显式地将对象强制类型转换成另外一种类型.例如,如果想在下面的代码中执行浮点数除法: int i, j; double slope = i / j; 就要使用某种方法将i和/或j显式地转换成 ...

  5. php获取当前时间和转换格式

    ## 获取时间和转换格式```//1.time():返回当前时间的Unix时间戳$stimestamp = time();$date = date("Y-m-d h:i:sa",$ ...

  6. Android的BroadcastReceiver 广播 短信拦截

    如何去理解BroadcastReceiver(广播)?其实可以这样想,首先我们要有一个发送广播的"媒体",在这个例子中,我们暂且用activity组件作为这个媒体,当然以后会用到s ...

  7. linux硬盘分区格式化及挂载

    1.硬盘的接口类型 硬盘的接口一般分为两种,一种是IDE并行接口,一种是SATA串行接口, 在linux上面IDE接口的硬盘被识别为/dev/hd[a-z]这样的设备,其中hdc表示光驱设备,这是因为 ...

  8. Undefined symbols for architectureIOS

    IOS问题解决. 现在进行老项目的编译,发现不能编译. 经过各种盲目查询,找个几个方案. 1.builde setting修改编译方式. 2.Builde Phases(修改). 2.1.库. 2.1 ...

  9. memcached完全剖析系列——一、memcached基础

    转自:http://blog.charlee.li/memcached-001/

  10. 分布式算法一——一致性hash算法

    摘自:http://blog.csdn.net/sparkliang/article/details/5279393