1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <iomanip>
  6. #include <cassert>
  7. #include <bitset>
  8. #include <cctype>
  9. #include <cstdio>
  10. #include <string>
  11. #include <vector>
  12. #include <stack>
  13. #include <cmath>
  14. #include <queue>
  15. #include <list>
  16. #include <map>
  17. #include <set>
  18. using namespace std;
  19. const int maxn=;
  20. const double eps=1e-;
  21. int sgn(double x){ if(fabs(x) < eps) return ; if(x >) return ; return -; }
  22. int dcmp(double x, double y){ if(fabs(x - y) < eps) return ; if(x > y) return ;return -;}
  23. struct Point { double x,y; Point(double x,double y) { x=x;y=y; }; Point() {}; };
  24. struct Segment{ Point a,b; Segment(Point x,Point y ) { a=x;b=y; }; Segment(){}; };
  25. struct Line { Point a,b; Line(Point x,Point y ) { a=x;b=y; }; Line(){}; };
  26. typedef Point Vector;
  27. /*Vector operator + (Vector A, Vector B){ return Vector(A.x+B.x, A.y+B.y); } // 向量相加
  28. Vector operator - (Point A, Point B){ return Vector(B.x-A.x, B.y-A.y); } // 向量生成 A-B;
  29. double operator * (Vector A, Vector B){ return A.x*B.x-A.y*B.y; } // 点积
  30. double operator ^ (Vector A, Vector B){ return A.x*B.y-A.y*B.x; } // 叉积*/
  31. double Dot(Vector A, Vector B) { return A.x*B.x + A.y*B.y; } // 点积
  32. double Cross(Vector A, Vector B) { return A.x*B.y-A.y*B.x; } // 叉积
  33. double Length(Vector A) { return sqrt(Dot(A, A)); } // 向量长度
  34. double dis(Point a,Point b) { return sqrt( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) ); }
  35. Point pa[maxn];
  36. Point pb[maxn];
  37. Line sg[maxn];
  38. int n;
  39. double make(Line A,Line B)
  40. {
  41. Point a=A.a; Point b=A.b;Point c=B.a; Point d=B.b;
  42. double A1=b.y-a.y,B1=-(b.x-a.x),C1=b.y*a.x-b.x*a.y;
  43. double A2=d.y-c.y,B2=-(d.x-c.x),C2=d.y*c.x-d.x*c.y;
  44. double k=A1*B2-A2*B1;
  45. double x=-(B1*C2-C1*B2)*1.000000000/k;
  46. double y=(A1*C2-C1*A2)*1.00000000/k;
  47. return x;
  48. }
  49. bool co(Line A,Line B)
  50. {
  51. Point a=A.a; Point b=A.b; Point c=B.a; Point d=B.b;
  52. Vector x,y,xxx,yyy;
  53. x.x=c.x-a.x; x.y=c.y-a.y;
  54. y.x=d.x-a.x; y.y=d.y-a.y;
  55. xxx.x=c.x-b.x; xxx.y=c.y-b.y;
  56. yyy.x=d.x-b.x; yyy.y=d.y-b.y;
  57. if( Cross(x,y)*Cross(xxx,yyy)>eps ) return ;
  58. else return ;
  59. }
  60. double work(Point xx,Point yy)
  61. {
  62. Line qq; qq.a=xx; qq.b=yy;
  63.  
  64. //cout<<xx.x<<" "<<xx.y<<endl;
  65. //cout<<yy.x<<" "<<yy.x<<endl;
  66.  
  67. double ans=-1e18;
  68. for(int i=;i<=n;i++)
  69. {
  70.  
  71. if(i==)
  72. {
  73. if(co(sg[i],qq)==) return ans;
  74. }
  75. else
  76. {
  77. if(co(sg[i],qq)==) ans=max(ans,make(sg[i],qq));
  78. else
  79. {
  80. if(co(Line(pa[i],pa[i-]),qq)==) ans=max(ans,make(Line(pa[i],pa[i-]),qq));
  81. if(co(Line(pb[i],pb[i-]),qq)==) ans=max(ans,make(Line(pb[i],pb[i-]),qq));
  82. break;
  83. }
  84. }
  85. }
  86. return ans;
  87. }
  88. bool up(Point a,Point b)
  89. {
  90. return a.x<b.x;
  91. }
  92. int main()
  93. {
  94. while()
  95. {
  96. scanf("%d",&n); if(n==) { break; }
  97. for(int i=;i<=n;i++) { scanf("%lf %lf",&pa[i].x,&pa[i].y); } // xia mian dian
  98. sort(pa+,pa++n,up);
  99. for(int i=;i<=n;i++) { pb[i].x=pa[i].x; pb[i].y=pa[i].y+1.0; } // shang mian dian
  100. for(int i=;i<=n;i++) { pa[i].y--; pb[i].y--; } // 下移
  101. for(int i=;i<=n;i++) { sg[i].a=pa[i]; sg[i].b=pb[i]; } // a xiao b shang
  102. double ans=-1e18;
  103. for(int i=;i<=n;i++)
  104. {
  105. for(int j=i+;j<=n;j++) // end
  106. {
  107. ans=max(ans,work(pa[i],pa[j]));
  108. ans=max(ans,work(pa[i],pb[j]));
  109. ans=max(ans,work(pb[i],pa[j]));
  110. ans=max(ans,work(pb[i],pb[j]));
  111. }
  112. //cout<<ans<<endl;
  113. }
  114. if(fabs(ans-pa[n].x)>eps ) printf("%.2f\n",ans);
  115. else printf("Through all the pipe.\n");
  116. }
  117. return ;
  118. }

poj 1039的更多相关文章

  1. poj 1039 Pipe(叉乘。。。)

    题目:http://poj.org/problem?id=1039 题意:有一宽度为1的折线管道,上面顶点为(xi,yi),所对应的下面顶点为(xi,yi-1),假设管道都是不透明的,不反射的,光线从 ...

  2. POJ - 1039 Pipe(计算几何)

    http://poj.org/problem?id=1039 题意 有一宽度为1的折线管道,上面顶点为(xi,yi),所对应的下面顶点为(xi,yi-1),假设管道都是不透明的,不反射的,光线从左边入 ...

  3. POJ 1039 Pipe【经典线段与直线相交】

    链接: http://poj.org/problem?id=1039 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  4. poj 1039 Pipe (Geometry)

    1039 -- Pipe 理解错题意一个晚上._(:з」∠)_ 题意很容易看懂,就是要求你求出从外面射进一根管子的射线,最远可以射到哪里. 正解的做法是,选择上点和下点各一个,然后对于每个折点位置竖直 ...

  5. nyoj 142, poj 1039 ,hdu 1454 管道问题

    http://acm.nyist.net/JudgeOnline/problem.php?pid=142 第一道解析几何问题,比较纠结,主要是几个解析几何的基本操作,包括求两线段的叉积,判断左右方向, ...

  6. 简单几何(直线与线段相交) POJ 1039 Pipe

    题目传送门 题意:一根管道,有光源从入口发射,问光源最远到达的地方. 分析:黑书上的例题,解法是枚举任意的一个上顶点和一个下顶点(优化后),组成直线,如果直线与所有竖直线段有交点,则表示能穿过管道. ...

  7. POJ 1039问题描述

    Description The GX Light Pipeline Company started to prepare bent pipes for the new transgalactic li ...

  8. POJ 1039 Pipe(直线和线段相交判断,求交点)

    Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8280   Accepted: 2483 Description ...

  9. POJ 1039 Pipe

    题意:一根管子,中间有一些拐点,给出拐点的上坐标,下坐标为上坐标的纵坐标减1,管子不能透过光线也不能折射光线,问光线能射到最远的点的横坐标. 解法:光线射到最远处的时候一定最少经过两个拐点,枚举每两个 ...

  10. poj 1039 Pipe(几何基础)

    Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9932   Accepted: 3045 Description ...

随机推荐

  1. Android系统中是否开启定位及定位模式的判断

    1.关于Android系统中不同的定位模式 Android系统中包括3中定位模式:   使用GPS.WLAN和移动网络 使用WLAN和移动网络 仅使用GPS 截图 特点 同时使用GPS.WIFI及基站 ...

  2. egret 简单的四方向的a星寻路,在wing中可以直接跑

    /** * main类中加载场景 * 创建游戏场景 * Create a game scene */ private createGameScene() { MtwGame.Instance.init ...

  3. tar: Exiting with failure status due to previous errors

    发生在tar压缩或者解压缩的过程中,原因是压缩包在建立的时候是用了sudo的,所以你解压的时候也要加上sudo,问题就很好解决了的

  4. Annotation(注解)介绍

    Annotation(注解)是什么: Annotation(注解) 官方的定义:    An annotation is a form of metadata, that can be added t ...

  5. L342 Air Pollution Is Doing More Than Just Slowly Killing Us

    Air Pollution Is Doing More Than Just Slowly Killing Us In the future, the authorities might need to ...

  6. nc/netcat命令

    nc/netcat命令 语法 nc/netcat(选项)(参数) 选项 -g<网关>:设置路由器跃程通信网关,最多设置8个: -G<指向器数目>:设置来源路由指向器,其数值为4 ...

  7. Spark笔记

    Spark基础 第一节:什么是Spark?Spark的特点和结构 1.什么是Spark? Spark是一个针对大规模数据处理的快速通用引擎. 类似MapReduce,都进行数据的处理 2.Spark的 ...

  8. 以编程方式使用 Microsoft Office Visio 2003 ActiveX 控件

    以编程方式使用 Microsoft Office Visio 2003 ActiveX 控件 2007/10/29 Mark BukovecEmpire Down Development 适用于:Mi ...

  9. 如何将本地的文件上传到你的github仓库中(首次流程)

    1.(先进入项目文件夹,右键项目文件夹,选择git Bash)通过命令 git init 把这个目录变成git可以管理的仓库 git init 2.把文件添加到版本库中,使用命令 git add . ...

  10. wav文件系列_2_Python实现读写

    本文介绍了 Python 实现音频读写的方法.Python wave 模块提供便捷的 wav 文件操作.该模块并不支持压缩与解压,但支持单声道/立体声的转换. 参考: [1] wave — Read ...