题意:一根管子,中间有一些拐点,给出拐点的上坐标,下坐标为上坐标的纵坐标减1,管子不能透过光线也不能折射光线,问光线能射到最远的点的横坐标。

解法:光线射到最远处的时候一定最少经过两个拐点,枚举每两个顶点,判断最远光线射到的位置。代码姿势不够优美……都是眼泪啊

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
const double eps = 1e-, inf = 9999999.0;
struct point
{
double x, y;
} up[], down[];
int n;
double cross(point p1, point p2, point p3)
{
return (p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y);
}
int judge(point a, point b)
{
for(int i = ; i < n; i++)
{
double tmp = cross(a, b, up[i]) * cross(a, b, down[i]);
if(tmp > eps)
return i;
}
return -;
}
int main()
{
while(~scanf("%d", &n) && n)
{
double ans = -inf;
int flag = ;
for(int i = ; i < n; i++)
{
double a, b;
scanf("%lf%lf", &a, &b);
up[i].x = down[i].x = a;
up[i].y = b, down[i].y = b - 1.0;
}
for(int i = ; i < n; i++)
for(int j = i + ; j < n; j++)
{
int tmp = judge(up[i], down[j]);
if(tmp >= )
{
double res;
if(tmp < j)
continue;
if(cross(up[i], down[j], up[tmp]) > )
{
double tmp1, tmp2;
tmp1 = cross(up[i], down[j], down[tmp - ]);
tmp2 = cross(up[i], down[j], down[tmp]);
res = (tmp2 * down[tmp - ].x - tmp1 * down[tmp].x) / (tmp2 - tmp1);
}
else
{
double tmp1, tmp2;
tmp1 = cross(up[i], down[j], up[tmp - ]);
tmp2 = cross(up[i], down[j], up[tmp]);
res = (tmp2 * up[tmp - ].x - tmp1 * up[tmp].x) / (tmp2 - tmp1);
}
ans = max(ans, res);
}
else
flag = ;
}
for(int i = ; i < n; i++)
for(int j = i + ; j < n; j++)
{
int tmp = judge(down[i], up[j]);
if(tmp >= )
{
double res;
if(tmp < j)
continue;
if(cross(down[i], up[j], up[tmp]) > )
{
double tmp1, tmp2;
tmp1 = cross(down[i], up[j], down[tmp - ]);
tmp2 = cross(down[i], up[j], down[tmp]);
res = (tmp2 * down[tmp - ].x - tmp1 * down[tmp].x) / (tmp2 - tmp1);
}
else
{
double tmp1, tmp2;
tmp1 = cross(down[i], up[j], up[tmp - ]);
tmp2 = cross(down[i], up[j], up[tmp]);
res = (tmp2 * up[tmp - ].x - tmp1 * up[tmp].x) / (tmp2 - tmp1);
}
ans = max(ans, res);
}
else
flag = ;
}
if(flag)
puts("Through all the pipe.");
else
printf("%.2f\n", ans);
}
return ;
}

POJ 1039 Pipe的更多相关文章

  1. poj 1039 Pipe (Geometry)

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

  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 题意 有一宽度为1的折线管道,上面顶点为(xi,yi),所对应的下面顶点为(xi,yi-1),假设管道都是不透明的,不反射的,光线从左边入 ...

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

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

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

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

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

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

  7. poj 1039 Pipe(几何基础)

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

  8. POJ 1039 Pipe 枚举线段相交

    Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9493   Accepted: 2877 Description ...

  9. POJ 1039 Pipe | 线段相交

    题目: 给一个管子,有很多转弯处,问从管口的射线射进去最长能射到多远 题解: 根据黑书,可以证明的是这条光线一定经过了一个上顶点和下顶点 所以我们枚举每对上下顶点就可以了 #include<cs ...

随机推荐

  1. MVC5+EF6+BootStrap3.3.5 博客系统之EF(一)

  2. 【BZOJ1251】序列终结者

    Description 网上有许多题,就是给定一个序列,要你支持几种操作:A.B.C.D.一看另一道题,又是一个序列 要支持几种操作:D.C.B.A.尤其是我们这里的某人,出模拟试题,居然还出了一道这 ...

  3. 搭建Git Server

    windows上如何搭建Git Server   Git在版本控制方面,相比与SVN有更多的灵活性,对于开源的项目,我们可以托管到Github上面,非常方便,但是闭源的项目就会收取昂贵的费用.那么私有 ...

  4. Mac下安装Redis图解教程

    去redis官网(http://redis.io/download)自行下载安装包解压缩到本地文件夹,比如放在Mac应用程序文件夹(/Applications/),在终端进入redis文件夹. 需要进 ...

  5. ParentChildTest.java

    public class ParentChildTest { public static void main(String[] args) { Parent parent=new Parent(); ...

  6. maven 编译部署src/main/java下的资源文件

    maven 编译部署src/main/java下的资源文件 maven默认会把src/main/resources下的所有配置文件以及src/main/java下的所有java文件打包或发布到targ ...

  7. 你不需要jQuery(四)

    jQuery是个好东西.它诞生于IE6在互联网称霸的那个时代.jQuery的存在让我们的代码能很好的兼容各种平台. 然而,到如今,浏览器技术已经取得了巨大的进步.我们可以自由的使用所有最新众多ES5/ ...

  8. 破解之寻找OEP[手动脱壳](1)

    OEP:(Original Entry Point),程序的入口点,软件加壳就是隐藏了OEP(或者用了假的OEP), 只要我们找到程序真正的OEP,就可以立刻脱壳. PUSHAD (压栈) 代表程序的 ...

  9. 作为 .Net 攻城师,所必需掌握的 .Net Profiling 技术

    众所周知,性能问题是所有实用应用在迭代过程中必然要面对的问题.对于此类问题,简单地投入更多硬件资源的做法可能会取得一定效果.但总的来看,此类做法的边际成本是不断上升的.换言之,随着性能需求的上涨,要换 ...

  10. poj 2065 SETI 高斯消元

    看题就知道要使用高斯消元求解! 代码如下: #include<iostream> #include<algorithm> #include<iomanip> #in ...