链接

枚举两点 若不和任何线段相交 建边为dis(i,j) floyd求最短路

  1. #include <iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<stdlib.h>
  6. #include<vector>
  7. #include<cmath>
  8. #include<queue>
  9. #include<set>
  10. using namespace std;
  11. #define N 100
  12. #define LL long long
  13. #define INF 0xfffffff
  14. const double eps = 1e-;
  15. const double pi = acos(-1.0);
  16. const double inf = ~0u>>;
  17. struct point
  18. {
  19. double x,y;
  20. point(double x=,double y=):x(x),y(y){}
  21. }p[N];
  22. struct line
  23. {
  24. point u,v;
  25. }li[N];
  26. double w[N][N];
  27. typedef point pointt;
  28. pointt operator - (point a,point b)
  29. {
  30. return pointt(a.x-b.x,a.y-b.y);
  31. }
  32. int dcmp(double x)
  33. {
  34. if(fabs(x)<eps) return ;
  35. return x<?-:;
  36. }
  37. double dis(point a)
  38. {
  39. return sqrt(a.x*a.x+a.y*a.y);
  40. }
  41. double cross(point a,point b)
  42. {
  43. return a.x*b.y-a.y*b.x;
  44. }
  45. bool segprointer(point a1,point a2,point b1,point b2)
  46. {
  47. double c1 = cross(a2-a1,b1-a1),c2 = cross(a2-a1,b2-a1),
  48. c3 = cross(b2-b1,a1-b1),c4 = cross(b2-b1,a2-b1);
  49. return dcmp(c1)*dcmp(c2)<&&dcmp(c3)*dcmp(c4)<;
  50. }
  51. int main()
  52. {
  53. int n,i,j,k;
  54. while(scanf("%d",&n)!=EOF)
  55. {
  56. if(n==-) break;
  57. int g = ;
  58. for(i = ; i <= ; i++)
  59. {
  60. for(j = ; j<= ; j++)
  61. w[i][j] = INF;
  62. w[i][i] = ;
  63. }
  64. int o = ;
  65. for(i = ; i <= n ;i++)
  66. {
  67. double k;
  68. scanf("%lf",&k);
  69. for(j = ; j <= ; j++)
  70. {
  71. p[++g].x = k;
  72. scanf("%lf",&p[g].y);
  73. }
  74. point pp = point(k,);
  75. li[++o].u = pp;
  76. li[o].v = p[g-];
  77. li[++o].u = p[g-];
  78. li[o].v = p[g-];
  79. li[++o].u = p[g];
  80. pp = point(k,);
  81. li[o].v = pp;
  82. }
  83. p[g+] = point(,);
  84. p[g+] = point(,);
  85. //printf("%d\n",segprointer(p[g+1],p[g+2],li[5].u,li[5].v));
  86. for(i = ; i <= g+; i++)
  87. for(j = i+; j <= g+; j++)
  88. {
  89. if(i==j) continue;
  90. for(k = ; k <= o ; k++)
  91. {
  92. if(segprointer(p[i],p[j],li[k].u,li[k].v))break;
  93.  
  94. }
  95. if(k>o)
  96. w[i][j] = w[j][i] = dis(p[i]-p[j]);
  97. //printf("%.2f %.2f %.2f %.2f %.2f\n",p[i].x,p[i].y,p[j].x,p[j].y,w[i][j]);
  98. }
  99. for(i = ; i <= g+ ; i++)
  100. for(j = ; j <=g+ ;j++)
  101. for(k = ; k <= g+ ; k++)
  102. w[j][k] = min(w[j][i]+w[i][k],w[j][k]);
  103. printf("%.2f\n",w[g+][g+]);
  104. }
  105. return ;
  106. }

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. JavaEE基础(二十六)/网络

    1.网络编程(网络编程概述) A:计算机网络 是指将地理位置不同的具有独立功能的多台计算机及其外部设备,通过通信线路连接起来,在网络操作系统,网络管理软件及网络通信协议的管理和协调下,实现资源共享和信 ...

  2. NSData NSDate NSString NSArray NSDictionary 相互转换

    // NSData NSDate NSString NSArray NSDictionary json NSString *string = @"hello word"; NSDa ...

  3. 解决php与IIs的冲突

    ISS与apache 服务器的默认端口号为 :80: 在浏览时,无法访问到. 可以将 apache的端口 改变即可: Apache安装好后,在其安装目录下的conf文件夹内会有httpd.conf这样 ...

  4. StringComparison枚举

    public enum StringComparison { CurrentCulture, CurrentCultureIgnoreCase, InvariantCulture, Invariant ...

  5. Poj(2135),MCMF,模板

    题目链接:http://poj.org/problem?id=2135 Farm Tour Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  6. SharePoint自动化系列——创建MMS terms

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ PowerShell脚本实现MMS group.termSet.terms的自动化创建: Add- ...

  7. 零零碎碎写的shell脚本(三):一键自动归档压缩脚本

    #!/bin/bash # author by sysk read -p "There files: " FILE1 FILE2 FILE3 read -p "Desti ...

  8. CentOS6.5下安装wine OK

    这篇文章主要记录了如何在CentOS 6.5上安装Wine 1.7.24开发版 1.安装需要的软件包 # yum groupinstall ‘Development Tools‘ # yum inst ...

  9. thinkphp model层外挪,以便多个站点可以通用

    /ThinkPHP/ThinkPHP.php  增加如下代码 //非原始代码defined('BASE_LOGIC') or define('BASE_LOGIC', THINK_PATH . '.. ...

  10. .Net用户控件

    用户控件用户控件是个什么东西?自定义的反复重用的控件集合 好处?1.代码重用2.结构良好3.分工开发4.局部缓存 难点:一.交换信息: 注意信息的交换只在相邻层之间进行交换,如果是嵌套交换信息除Ses ...