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 ...
随机推荐
- SQLSERVER 更改默认端口号
最近这几天,服务器的数据库(SQLSERVER)老是遭受到攻击,有人不断地轮训想登陆数据库,从SQL的日志里可以看出来,一开始我是通过本地安全策略禁用了对应的几个攻击ip,同时把数据库的sa账号给禁用 ...
- poj 2262 Goldbach's Conjecture(素数筛选法)
http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS Memory Limit: 65536K Total ...
- poj 1679 The Unique MST(唯一的最小生成树)
http://poj.org/problem?id=1679 The Unique MST Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
- [转]BluetoothDevice.getType()-一个常常被忽略了的函数。好用的不要不要的
自动安卓发布了4.0版本的蓝牙协议之后,越来越多的开发者收到了各种针对于BLE蓝牙的开发需求. 而且有很多时候还需要兼容以前的3.0版本,给大家的开发带来了困扰,笔者也遇到了这样的问题,偶然间发现了g ...
- idea14使用maven创建web工程
参考博客:http://geeksun.iteye.com/blog/2179658 http://www.bubuko.com/infodetail-387387.html ------------ ...
- jquery中json数据转换为字典
首先在前台页面中的json数据为 var recipe = {}; recipe["name"] = $("#name").val(); recipe[&quo ...
- python常用web框架性能测试(django,flask,bottle,tornado)
测了一下django.flask.bottle.tornado 框架本身最简单的性能.对django的性能完全无语了. django.flask.bottle 均使用gunicorn+gevent启动 ...
- lib和dll文件的区别和联系
什么是lib文件,lib和dll的关系如何 (2008-04-18 19:44:37) (1)lib是编译时需要的,dll是运行时需要的. 如果要完成源代码的编译,有lib就够了. 如果也使动态 ...
- maven 如何解决因本地jar导致的编译错误
如何解决Maven依赖本地非repository中的jar包,依赖jar包放在WEB-INF/lib等目录下的情况客户端编译出错的处理.http://www.mamicode.com/info-det ...
- 缺少编译器要求的成员“System.Runtime.CompilerServices.ExtensionAttribute..ctor” 解决方案
静态类中添加如下.此方法本人测试有效. //缺少编译器要求的成员“ystem.Runtime.CompilerServices.ExtensionAttribute..ctor” namespace ...