poj1556The Doors
枚举两点 若不和任何线段相交 建边为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的更多相关文章
- ACM/ICPC 之 最短路径-Bellman Ford范例(POJ1556-POJ2240)
两道Bellman Ford解最短路的范例,Bellman Ford只是一种最短路的方法,两道都可以用dijkstra, SPFA做. Bellman Ford解法是将每条边遍历一次,遍历一次所有边可 ...
- poj 1556 The Doors
The Doors Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u Java ...
- POJ 1556 The Doors(线段交+最短路)
The Doors Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5210 Accepted: 2124 Descrip ...
- 100 doors
Question There are 100 doors in a row that are all initially closed. You make 100 passes by the door ...
- poj 1556 The Doors(线段相交,最短路)
The Doors Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7430 Accepted: 2915 Descr ...
- POJ 1556 The Doors 线段判交+Dijkstra
The Doors Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6734 Accepted: 2670 Descrip ...
- POJ 1556 - The Doors 线段相交不含端点
POJ 1556 - The Doors题意: 在 10x10 的空间里有很多垂直的墙,不能穿墙,问你从(0,5) 到 (10,5)的最短距离是多少. 分析: 要么直达,要么 ...
- POJThe Doors AND NYIST 有趣的问题
POJThe Doors AND NYIST 有趣的问题 题目链接:pid=227" target="_blank">Click Here~ 题目分析: 给你横纵坐 ...
- 【DOORS】如何基于DOORS实施需求管理
引言 IBM Rational DOORS,简称DOORS,是被业界广泛认可的需求管理工具,在国内外需求管理领域具有较高的市场占有率.需求管理作为传统的工程领域,理论发展相对成熟和健全.随着越来越多的 ...
随机推荐
- JavaEE基础(二十六)/网络
1.网络编程(网络编程概述) A:计算机网络 是指将地理位置不同的具有独立功能的多台计算机及其外部设备,通过通信线路连接起来,在网络操作系统,网络管理软件及网络通信协议的管理和协调下,实现资源共享和信 ...
- NSData NSDate NSString NSArray NSDictionary 相互转换
// NSData NSDate NSString NSArray NSDictionary json NSString *string = @"hello word"; NSDa ...
- 解决php与IIs的冲突
ISS与apache 服务器的默认端口号为 :80: 在浏览时,无法访问到. 可以将 apache的端口 改变即可: Apache安装好后,在其安装目录下的conf文件夹内会有httpd.conf这样 ...
- StringComparison枚举
public enum StringComparison { CurrentCulture, CurrentCultureIgnoreCase, InvariantCulture, Invariant ...
- Poj(2135),MCMF,模板
题目链接:http://poj.org/problem?id=2135 Farm Tour Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- SharePoint自动化系列——创建MMS terms
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ PowerShell脚本实现MMS group.termSet.terms的自动化创建: Add- ...
- 零零碎碎写的shell脚本(三):一键自动归档压缩脚本
#!/bin/bash # author by sysk read -p "There files: " FILE1 FILE2 FILE3 read -p "Desti ...
- CentOS6.5下安装wine OK
这篇文章主要记录了如何在CentOS 6.5上安装Wine 1.7.24开发版 1.安装需要的软件包 # yum groupinstall ‘Development Tools‘ # yum inst ...
- thinkphp model层外挪,以便多个站点可以通用
/ThinkPHP/ThinkPHP.php 增加如下代码 //非原始代码defined('BASE_LOGIC') or define('BASE_LOGIC', THINK_PATH . '.. ...
- .Net用户控件
用户控件用户控件是个什么东西?自定义的反复重用的控件集合 好处?1.代码重用2.结构良好3.分工开发4.局部缓存 难点:一.交换信息: 注意信息的交换只在相邻层之间进行交换,如果是嵌套交换信息除Ses ...