链接

枚举两点 若不和任何线段相交 建边为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. Spring中@Cacheable的用法

    在Spring中通过获取MemCachedClient来实现与memcached服务器进行数据读取的方式.不过,在实际开发中,我们往往是通过Spring的@Cacheable来实现数据的缓存的,所以, ...

  2. linux正则表达式使用

    首先介绍下正则表达式,它是由一串字符和元字符构成的字符串,简称RE(Regular Expression),它的主要功能是文本查询和字符串操作,它可以匹配一个文本的字符和字符集,达到数据过滤的效果. ...

  3. android FragmentPagerAdapter getItem方法没有执行

    转自 http://blog.csdn.net/getchance/article/details/40263505 在一个 Android 应用中,我使用 FragmentPagerAdapter  ...

  4. android 代码整体回退

    repo forall -c 'HAHA=`git log --before="3 days" -1 --pretty=format:"%H"`;git res ...

  5. c#之xml

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.X ...

  6. The Happy Worm 分类: POJ 排序 2015-08-03 18:57 5人阅读 评论(0) 收藏

    The Happy Worm Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 4698 Accepted: 1047 Descr ...

  7. 多校赛3- Painter 分类: 比赛 2015-07-29 19:58 3人阅读 评论(0) 收藏

    D - Painter Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status P ...

  8. Unity中实现List类型的自定义GUI(ReorderableList)

    感谢韩同学提供的资源 Unity本身提供了float,int,vector3..等类型字段的gui接口,而对于集合类型一般要自己硬写. 官方提供了一个List的自定义GUI,但使用起来非常复杂 Uni ...

  9. Entity Framework 第五篇 状态跟踪

    本人建议尽量使用EntityState来表名Entry的状态,而不要使用Configuration.AutoDetectChangesEnabled自动状态跟踪,为什么我这么建议呢?他们到底有什么异同 ...

  10. tomcant报错The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path

    下载与你Tomcat对应版本的 tcnative-1.dll,放到apache-tomcat-7.0.57\bin 目录下,重启tomcat http://archive.apache.org/dis ...