嘟嘟嘟




大致题意:按顺序给出\(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的更多相关文章

  1. poj1039 Pipe【计算几何】

    含[求直线交点].[判断直线与线段相交]模板   Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:11940   Ac ...

  2. poj1039 Pipe(计算几何叉积求交点)

    F - Pipe Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  3. Pipe(点积叉积的应用POJ1039)

    Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9723   Accepted: 2964 Description ...

  4. hdoj Pipe&&南阳oj管道问题&&poj1039(计算几何问题...枚举)

    Pipe Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  5. angular2系列教程(六)两种pipe:函数式编程与面向对象编程

    今天,我们要讲的是angualr2的pipe这个知识点. 例子

  6. 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 ...

  7. TNS-12518 & Linux Error:32:Broken pipe

    最近一周,有一台ORACLE数据库服务器的监听服务在凌晨2点过几分的时间点突然崩溃,以前从没有出现过此类情况,但是最近一周出现了两次这种情况,检查时发现了如下一些信息: $ lsnrctl servi ...

  8. -bash: ulimit: pipe size: cannot modify limit: Invalid argument

    从root账号切换到oracle账号时,出现了"-bash: ulimit: pipe size: cannot modify limit: Invalid argument"提示 ...

  9. Linux进程间通信(三):匿名管道 popen()、pclose()、pipe()、close()、dup()、dup2()

    在前面,介绍了一种进程间的通信方式:使用信号,我们创建通知事件,并通过它引起响应,但传递的信息只是一个信号值.这里将介绍另一种进程间通信的方式——匿名管道,通过它进程间可以交换更多有用的数据. 一.什 ...

随机推荐

  1. 四、cent OS安装配置mysql

    下载mysql的repo源wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 安装mysql-community-r ...

  2. 从JSON中读取数据追加到HTML中

    本文来自https://www.jianshu.com/p/04127d74d88c,并非本人原创,只是作为自己学习使用的资料,如有浏览者请点击地址自行到原作者页面浏览 有时候我们需要将json数据直 ...

  3. 浅谈arguments与arguments的妙用

    1.每个函数都有一个arguments属性,表示函数的实参集合,这里的实参是重点,就是执行函数时实际传入的参数的集合. 2.arguments不是数组而是一个对象,但它和数组很相似,所以通常称为类数组 ...

  4. UOJ#54 BZOJ3434 [WC2014]时空穿梭

    题目描述 小 X 驾驶着他的飞船准备穿梭过一个 \(n\) 维空间,这个空间里每个点的坐标可以用 \(n\) 个实数表示,即 \((x_1,x_2,\dots,x_n)\). 为了穿过这个空间,小 X ...

  5. 旋转/非旋转treap的简单操作

    treap(树堆) 是在二叉搜索树的基础上,通过维护随机附加域,使其满足堆性质,从而使树相对平衡的二叉树: 为什么可以这样呢? 因为在维护堆的时候可以同时保证搜索树的性质: (比如当一棵树的一个域满足 ...

  6. java简单数组定义

    public class Shuzu { static int[] array = new int[] { 32, 2, 2, 5, 45, }; int[] array1[] = new int[1 ...

  7. JS 数据容量转换/换算

    function diskSize(num){ if (num == 0) return '0 B'; var k = 1024; //设定基础容量大小 var sizeStr = ['B','KB' ...

  8. Tomcat部署路径空格问题

    web项目发布到tomcat下,如果tomcat安装目录为 C:\Program Files\tomcat6\webapps\... 当我们获取当前类的路径时,就会出现空格(%20)问题 C:\Pro ...

  9. Android学习笔记(2)----LocationManager的使用

    今天使用Android的LocationManager制作了一款获取当前经纬坐标位置的软件. LocationManager获取的只是经纬坐标点,为了解析出当前经纬坐标点的实际位置,可以使用Googl ...

  10. PGIS大数据量点位显示方案

    PGIS大数据量点位显示方案 问题描述 PGIS在地图上显示点位信息时,随点位数量的增加浏览器响应速度会逐渐变慢,当同时显示上千个点时浏览器会变得非常缓慢,以下是进行的测试: 测试环境: 服务器: C ...