嘟嘟嘟




大致题意:按顺序给出\(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. RabbitMQ---8、连接断开处理-断线重连

    本文转载于:https://www.itsvse.com/thread-4636-1-1.html: 参考文献:http://www.likecs.com/show-29874.html:https: ...

  2. 百度搜索URL参数含义

    序号 参数 含义 1 tn 搜索框所属网站.比如 tn=sitehao123,就是 http://www.hao123.com/ 左上那个搜索框(指通过什么方式到达百度首页搜索界面;) 2 s?wd ...

  3. C#Json数据类型

    引用所对应框架的类库文件,下载地址:http://json.codeplex.com/ 在一般处理程序axhx中: 引用的命名空间: using System.IO;using Newtonsoft. ...

  4. 一:SpringCloud

    一:前提知识+相关说明 前提知识:springmvc+spring/springboot+mybatis+maven+git...... cloud技术的五大神兽: 面试题: 什么是微服务? 微服务之 ...

  5. 微服务系列(二):使用 API 网关构建微服务

    编者的话|本文来自 Nginx 官方博客,是微服务系列文章的第二篇,本文将探讨:微服务架构是如何影响客户端到服务端的通信,并提出一种使用 API 网关的方法. 作者介绍:Chris Richardso ...

  6. JMM和底层实现原理

  7. Web知识简易介绍及HTTP知识总结

    一.软件系统体系结构: 常见软件系统体系结构B/S.C/S C/S结构即客户端/服务器(Client/Server),例如QQ: 缺点:软件更新是需要同时更新客户端和服务器端两端,比较麻烦 优点:安全 ...

  8. CSS之Flex 布局

    Flex 布局教程:语法篇 网页布局(layout)是 CSS 的一个重点应用. 布局的传统解决方案,基于盒状模型,依赖 display 属性 + position属性 + float属性.它对于那些 ...

  9. 专访探探DBA张文升:PG在互联网应用中同样也跑的很欢畅

    张文升认为,PG无论在可靠性和性能方面都不输其它任何关系型数据库   张文升,探探DBA,负责探探的数据库架构.运维和调优的工作.拥有8年开发经验,曾任去哪儿网DBA.   9月24日,张文升将参加在 ...

  10. 然之协同系统6.4.1 SQL注入导致getshell

     前言 先知上一个大佬挖的洞,也有了简单的分析 https://xianzhi.aliyun.com/forum/topic/2135 我自己复现分析过程,漏洞的原理比较简单,但是漏洞的利用方式对我而 ...