嘟嘟嘟




大致题意:按顺序给出\(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. IoC容器之Unity

    关于IoC.Unity见博友文章点击这里. 话不多说,上程序HelloUnity,程序采用VS2010,Unity2.1. 1.程序框架如下 2.类库HelloUnity.Objects,主要为实体类 ...

  2. Vue 多路由文件的合并

    Vue 多路由文件的合并 1.使用的是ES6 数组的合并方法 let routes = new Set([...routes1, ...homerouters]);2.两个路由文件,导出的实际上就是一 ...

  3. 撩课-Web架构师养成系列(第二篇)-async

    前言 Web架构师养成系列共15篇,每周更新一篇,主要分享.探讨目前大前端领域(前端.后端.移动端)企业中正在用的各种成熟的.新的技术.部分文章也会分析一些框架的底层实现,让我们做到知其然知其所以然. ...

  4. 撩课-Java每天5道面试题第9天

    撩课Java+系统架构 视频 点击开始学习 76.XML技术的作用? XML技术用于数据存储. 信息配置. 数据交换三方面. 可以将数据存储在XML中, 通过节点. 元素内容. 属性标示数据内容及关系 ...

  5. 【SSH网上商城项目实战16】Hibernate的二级缓存处理首页的热门显示

    转自:https://blog.csdn.net/eson_15/article/details/51405911 网上商城首页都有热门商品,那么这些商品的点击率是很高的,当用户点击某个热门商品后需要 ...

  6. CodeForces 616A(水题)

    while(t--) 最后结果t=-1 #include <iostream> #include <string> #include <cstring> #incl ...

  7. Git和Github快速入门

    一.什么是Git? 假设你在的公司要上线一个新功能,你们开发团队为实现这个新功能,写了大约5000行代码,上线没2天,就发现这个功能用户并不喜欢,你老板让你去掉这个功能,你怎么办?你说简单,直接把50 ...

  8. webapi views目录下html文件无法访问

    找到views下web.config 增加如下红色标注内容 <?xml version="1.0"?> <configuration> <config ...

  9. JavaScript的进阶之路(四)理解对象1

    对象是JavaScript的基本数据类型.简单的名值对组成了对象,BUT:还可以从一个被称为原型的对象继承属性,对象的方法通常就是继承的属性. 对象最常见的用法有:创建.设置.查找.删除.检测.枚举它 ...

  10. toast, 警告窗

    //浮动提示框 1秒后消失 toast(msg, isError, sec) { var div = $('#toast'); div.html(msg); div.css({visibility: ...