题意:一根管子,中间有一些拐点,给出拐点的上坐标,下坐标为上坐标的纵坐标减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. VS 2005部署应用程序提示“应用程序无法正常启动( 0x0150002)” 解决方案

    遇到这个问题,一定是缺少了CRT.MFC.ATL的DLL,不同版本的VS是不一样的.系统自带这些库的Release版,如果没有自带,打补丁就有了:系统不自带这些库的Debug版,所以Debug版的程序 ...

  2. bnuoj 4357 传送阵

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=4357 [题意]:在1000个数中选择3个之和是m的倍数,可能有多种选择方案,请输出标号排序最小的一组 ...

  3. QR code 金庸小说体(二)

    传说 在二维码世纪,流传着这样一个传说,long long ago,武林一片混乱,这时魔教二长老创立了一门绝世武功——QR code,随后称霸武林.但同时也遭到武林中人的觊觎和反抗,各大武林正派掌门人 ...

  4. 2336: [HNOI2011]任务调度 - BZOJ

    一道随机算法的题目 随便用什么随机算法 首先我们可以想到枚举类型3的最终类型,然后再做 先贪心出一个较优的序列,首先我们知道肯定是在A机器上先做完类型1的事件再做类型2的事件,机器B也类似,因为这些没 ...

  5. firefly服务器间通信演示

    源地址:http://www.9miao.com/question-15-54560.html 最近好多童鞋都在问firefly几个服务器之间是如何通信的,其实在之前的distributed使用文档中 ...

  6. adt安装慢解决

    原地址:http://yuanzhifei89.iteye.com/blog/1884398 安装adt的时候不管时在线安装还是下载下来了离线安装,都不见安装进度条动,只要把一个选项勾掉立马就让进度条 ...

  7. nginx比较apache

    http://blog.csdn.net/hanghangaidoudou/article/details/8506963 话说nginx在大压力的环境中比apache的表现要好,于是下载了一个来折腾 ...

  8. nginx的负载均衡和反响代理配置

    4.        负载均衡配置 nginx 的 upstream默认是以轮询的方式实现负载均衡,这种方式中,每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除. 另外 ...

  9. 【转】VC++消息钩子编程

    VC++消息钩子编程

  10. 【转】notepad++ 应用学习 -- 列模式,十六进制模式

      Notepad++ 顾名思义,是一个比notepad(Windows下叫记事本)的功能更强的编辑器. 总以为notepad++小巧轻盈,而且开源,要比UE(UltraEdit)好用.因为她支持的视 ...