POJ 1039 Pipe
题意:一根管子,中间有一些拐点,给出拐点的上坐标,下坐标为上坐标的纵坐标减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的更多相关文章
- poj 1039 Pipe (Geometry)
1039 -- Pipe 理解错题意一个晚上._(:з」∠)_ 题意很容易看懂,就是要求你求出从外面射进一根管子的射线,最远可以射到哪里. 正解的做法是,选择上点和下点各一个,然后对于每个折点位置竖直 ...
- poj 1039 Pipe(叉乘。。。)
题目:http://poj.org/problem?id=1039 题意:有一宽度为1的折线管道,上面顶点为(xi,yi),所对应的下面顶点为(xi,yi-1),假设管道都是不透明的,不反射的,光线从 ...
- POJ - 1039 Pipe(计算几何)
http://poj.org/problem?id=1039 题意 有一宽度为1的折线管道,上面顶点为(xi,yi),所对应的下面顶点为(xi,yi-1),假设管道都是不透明的,不反射的,光线从左边入 ...
- POJ 1039 Pipe【经典线段与直线相交】
链接: http://poj.org/problem?id=1039 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- 简单几何(直线与线段相交) POJ 1039 Pipe
题目传送门 题意:一根管道,有光源从入口发射,问光源最远到达的地方. 分析:黑书上的例题,解法是枚举任意的一个上顶点和一个下顶点(优化后),组成直线,如果直线与所有竖直线段有交点,则表示能穿过管道. ...
- POJ 1039 Pipe(直线和线段相交判断,求交点)
Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8280 Accepted: 2483 Description ...
- poj 1039 Pipe(几何基础)
Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9932 Accepted: 3045 Description ...
- POJ 1039 Pipe 枚举线段相交
Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9493 Accepted: 2877 Description ...
- POJ 1039 Pipe | 线段相交
题目: 给一个管子,有很多转弯处,问从管口的射线射进去最长能射到多远 题解: 根据黑书,可以证明的是这条光线一定经过了一个上顶点和下顶点 所以我们枚举每对上下顶点就可以了 #include<cs ...
随机推荐
- HubbleDotNet开源全文搜索组件相关资源
系统简介 HubbleDotNet 是一个基于.net framework 的开源免费的全文搜索数据库组件.开源协议是 Apache 2.0.HubbleDotNet提供了基于SQL的全文检索接口,使 ...
- linux安装软件命令
tar.bz2的解压: tar -jxvf FileName.tar.bz2 然后安装: cd FileName ./configure make make install rpm 包的安装: rpm ...
- Buffer
Buffer 我们用原有 IO 读写文件应该不会陌生了,顺带回顾一下,大致两种: 1. 在 InputStream 或 OutputStream 上读写字节或字节数组,读 InputStream 时用 ...
- 下一代Jquery模板-----JsRender
在ASP.NET MVC利用PagedList分页(二)PagedList+Ajax+JsRender中提到了JsRender.JsRedner和JsViews(JsViews是再JsRender基础 ...
- Smarty格式化数字为INT数
<? require("setup.php"); define('PAGETITLE','pagtitle'); function insert_top($lid,$sid) ...
- uva 10105
数学 杨辉三角 多项式系数 #include <cstdio> int f[13] = {1}; void init() { for (int i = 1; i < 13; i+ ...
- javascript div z-index, input tabindex属性说明
<html> <body> <form> 用户名: <input type="text" tabindex="1" / ...
- 认识FiddlerScript
FiddlerScript 是Fiddler 的一项非常强大的功能,它允许你增强Fiddler UI,添加新的特性,修改请求与响应内容等等... 1.编写FiddlerScript FiddlerSc ...
- C++ 中判断非空的错误指针
最近在写网络上的东西,程序经过长时间的运行,会出现崩溃的问题,经过DUMP文件的查看,发现在recv的地方接收返回值的时候,数据的长度异常的大差不多16亿多字节.而查看分配后的char指针显示为错误的 ...
- 【转】PostgreSQL IP地址访问配置
原文:http://blog.csdn.net/shuaiwang/article/details/1793294 1.PostgreSQL的安装目录,进入data文件夹,打开postgresql.c ...