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()
在前面,介绍了一种进程间的通信方式:使用信号,我们创建通知事件,并通过它引起响应,但传递的信息只是一个信号值.这里将介绍另一种进程间通信的方式——匿名管道,通过它进程间可以交换更多有用的数据. 一.什 ...
随机推荐
- C#中使用Log4Net记录日志
https://www.cnblogs.com/W--Jing/p/8125652.html 实例参考 https://www.cnblogs.com/soundcode/p/4866078.html ...
- ASP.NET之Jquery入门级别
1.Jquery的简单介绍 1)Jquery由美国人John Resig创建.是继prototype之后又一个优秀的JavaScript框架. 2)JQuery能做什么?JQuery能做的普通的Dom ...
- 十一、信号量控制Semaphore
一.简介 有时候我们需要对一个资源的访问做线程数控制,以防雪崩等问题. JDK中,信号量可以处理这样的问题:Semaphore JDK文档:http://tool.oschina.net/upload ...
- vim 编辑器常规操作
所看视频教程:兄弟连Linux云计算视频教程5.1文本编辑器Vim-5.2 插入命令 a:在光标所在字符后插入; A:在光标所在行尾插入; i:在光标所在字符前插入; I:在光标所在字符行行首插入; ...
- mysql设置不区分大小写
1.windows下 到安装mysql的目录,修改my.ini文件 在文件最后一行加上下面一句话 lower_case_table_names=1 lower_case_table_names = 1 ...
- python用random产生验证码,以及random的一些其他用法
产生随机验证码函数 import random def get_code(): code = '' for i in range(5): num = str(random.randrange(10)) ...
- CentOS6下docker的安装和使用
CentOS6下docker的安装和使用 Docker是一个开源的应用容器引擎,可以轻松的为任何应用创建一个轻量级的.可移植的.自给自足的容器.利用Linux的LXC.AUFS.Go语言.cgroup ...
- Luogu3804:[模板]后缀自动机
题面 luogu Sol \(sam\)然后树形\(DP\) 当时还不会拓扑排序的我 # include <bits/stdc++.h> # define IL inline # defi ...
- Week2——XML
一.什么是XML? XML是可扩展标记性语言,类似于HTML,被设计为传输和存储数据,其焦点是数据的内容.XML的标签没有被预定义,用户就需要自行定义标签,也可随意定义标签.XML 允许创作者定义自己 ...
- mac下同时安装jdk1.7和jdk1.8
1.安装jdk1.7时会弹出报错,说版本不兼容. 解决方案 双击安装包,使安装包挂在到机器上,即在Finder里可以看到一个名字为JDK 7 Update 60的Device. 在terminal下输 ...