POJ1039 Pipe
嘟嘟嘟
大致题意:按顺序给出\(n\)个拐点表示一个管道,注意这些点是管道的上端点,下端点是对应的\((x_i, y_i - 1)\)。从管道口射进一束光,问能达到最远的位置的横坐标。若穿过管道,输出\(Through\) \(all\) \(the\) $ pipe.$
还是线段求交问题。
枚举端点作为直线(光束)上的两个点。然后判断这条直线和每一条线段\((x_i, y_i)(x_i, y_i - 1)\)是否有交点。若无,则求出最远能到达的\(x\)。
注意坐标可为负,所以刚开始的极小值为\(-INF\),而不是\(0\)。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 25;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
int n;
struct Vec
{
db x, y;
db operator * (const Vec& oth)const
{
return x * oth.y - oth.x * y;
}
};
struct Point
{
db x, y;
Vec operator - (const Point& oth)const
{
return (Vec){x - oth.x, y - oth.y};
}
}a[maxn], b[maxn];
db calc(Point A, Point B, Point C, Point D)
{
Vec AB = B - A, AC = C - A, AD = D - A, CD = D - C;
db s1 = fabs(AB * AC), s2 = fabs(AB * AD);
return C.x + CD.x / (s1 + s2) * s1;
}
db solve(Point A, Point B)
{
Vec AB = B - A;
for(int i = 1; i <= n; ++i)
{
Vec AC = a[i] - A, AD = b[i] - A;
if((AC * AB) * (AD * AB) > eps)
{
if(i == 1) return -INF;
Vec AE = a[i - 1] - A;
if((AE * AB) * (AC * AB) < -eps) return calc(A, B, a[i - 1], a[i]);
Vec AF = b[i - 1] - A;
if((AF * AB) * (AD * AB) < -eps) return calc(A, B, b[i - 1], b[i]);
return -INF;
}
}
return INF;
}
int main()
{
while(scanf("%d", &n) && n)
{
for(int i = 1; i <= n; ++i)
scanf("%lf%lf", &a[i].x, &a[i].y), b[i].x = a[i].x, b[i].y = a[i].y - 1;
db ans = -INF;
for(int i = 1; i < n && ans != INF; ++i)
{
for(int j = i + 1; j <= n; ++j)
{
ans = max(ans, solve(a[i], a[j]));
if(ans == INF) break;
ans = max(ans, solve(a[i], b[j]));
if(ans == INF) break;
ans = max(ans, solve(b[i], a[j]));
if(ans == INF) break;
ans = max(ans, solve(b[i], b[j]));
if(ans == INF) break;
}
}
if(ans == INF) puts("Through all the pipe.");
else printf("%.2f\n", ans);
}
return 0;
}
POJ1039 Pipe的更多相关文章
- poj1039 Pipe【计算几何】
含[求直线交点].[判断直线与线段相交]模板 Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions:11940 Ac ...
- poj1039 Pipe(计算几何叉积求交点)
F - Pipe Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- Pipe(点积叉积的应用POJ1039)
Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9723 Accepted: 2964 Description ...
- hdoj Pipe&&南阳oj管道问题&&poj1039(计算几何问题...枚举)
Pipe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- angular2系列教程(六)两种pipe:函数式编程与面向对象编程
今天,我们要讲的是angualr2的pipe这个知识点. 例子
- Non-blocking read on a subprocess.PIPE in python
import sys from subprocess import PIPE, Popen from threading import Thread try: from Queue import Qu ...
- TNS-12518 & Linux Error:32:Broken pipe
最近一周,有一台ORACLE数据库服务器的监听服务在凌晨2点过几分的时间点突然崩溃,以前从没有出现过此类情况,但是最近一周出现了两次这种情况,检查时发现了如下一些信息: $ lsnrctl servi ...
- -bash: ulimit: pipe size: cannot modify limit: Invalid argument
从root账号切换到oracle账号时,出现了"-bash: ulimit: pipe size: cannot modify limit: Invalid argument"提示 ...
- Linux进程间通信(三):匿名管道 popen()、pclose()、pipe()、close()、dup()、dup2()
在前面,介绍了一种进程间的通信方式:使用信号,我们创建通知事件,并通过它引起响应,但传递的信息只是一个信号值.这里将介绍另一种进程间通信的方式——匿名管道,通过它进程间可以交换更多有用的数据. 一.什 ...
随机推荐
- linux中find与rm实现查找并删除文件
find命令: find . -name '*.log' #查找当前目录下的log文件 查找并删除: find . -name '*.log' -type f -print -exec rm -rf ...
- Spring MVC No converter found for return value of type 解决方法
1.在pom中添加 jackson <properties> <jackson.version>2.8.5</jackson.version> </prope ...
- 使用webClient实现图片同步,异步下载
WebClient.DownloadFile 方法 将具有指定 URI 的资源下载到本地文件. 命名空间:System.Net 程序集:System(在 system.dll 中) 同步实现参考代码: ...
- CodeForces 614A(水题)
这道题有个需要注意的地方,就是范围大小 2^16 = 65535,2^32 = 65535(10^4),2^16 = 4294967295(10^9),2^64=9223372036854775807 ...
- unity3d之游戏优化
=============================================================================== 美术规格: 1.单个蒙皮网格渲染器2.一 ...
- N次剩余和二次剩余
N次剩余 给定 \(N,a,P\),且 \(P\) 最好为质数 可以算出 \(x^N\equiv a(mod~p)\) 的解 首先可以算出 \(P\) 的原根 \(g\) 解方程 \(g^y\equi ...
- Luogu4433:[COCI2009-2010#1] ALADIN(类欧几里德算法)
先套用一个线段树维护离散化之后的区间的每一段的答案 那么只要考虑怎么下面的东西即可 \[\sum_{i=1}^{n}(A\times i \ mod \ B)\] 拆开就是 \[\sum_{i=1}^ ...
- axios使用初涉
看vue的时候,vue2.0推荐使用axios做http请求,今天就学一下axios基本使用. 安装 axios 推荐npm方法(npm是node.js环境下的包管理器): npm install a ...
- easy canvas shape with react antdesign 简单的canvas图形in antd & react
//show: //code: import React from "react" import {findDOMNode} from 'react-dom' import { B ...
- 四元数(Quaternion)和旋转 +欧拉角
四元数介绍 旋转,应该是三种坐标变换--缩放.旋转和平移,中最复杂的一种了.大家应该都听过,有一种旋转的表示方法叫四元数.按照我们的习惯,我们更加熟悉的是另外两种旋转的表示方法--矩阵旋转和欧拉旋转. ...