poj 1039
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
using namespace std;
const int maxn=;
const double eps=1e-;
int sgn(double x){ if(fabs(x) < eps) return ; if(x >) return ; return -; }
int dcmp(double x, double y){ if(fabs(x - y) < eps) return ; if(x > y) return ;return -;}
struct Point { double x,y; Point(double x,double y) { x=x;y=y; }; Point() {}; };
struct Segment{ Point a,b; Segment(Point x,Point y ) { a=x;b=y; }; Segment(){}; };
struct Line { Point a,b; Line(Point x,Point y ) { a=x;b=y; }; Line(){}; };
typedef Point Vector;
/*Vector operator + (Vector A, Vector B){ return Vector(A.x+B.x, A.y+B.y); } // 向量相加
Vector operator - (Point A, Point B){ return Vector(B.x-A.x, B.y-A.y); } // 向量生成 A-B;
double operator * (Vector A, Vector B){ return A.x*B.x-A.y*B.y; } // 点积
double operator ^ (Vector A, Vector B){ return A.x*B.y-A.y*B.x; } // 叉积*/
double Dot(Vector A, Vector B) { return A.x*B.x + A.y*B.y; } // 点积
double Cross(Vector A, Vector B) { return A.x*B.y-A.y*B.x; } // 叉积
double Length(Vector A) { return sqrt(Dot(A, A)); } // 向量长度
double dis(Point a,Point b) { return sqrt( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) ); }
Point pa[maxn];
Point pb[maxn];
Line sg[maxn];
int n;
double make(Line A,Line B)
{
Point a=A.a; Point b=A.b;Point c=B.a; Point d=B.b;
double A1=b.y-a.y,B1=-(b.x-a.x),C1=b.y*a.x-b.x*a.y;
double A2=d.y-c.y,B2=-(d.x-c.x),C2=d.y*c.x-d.x*c.y;
double k=A1*B2-A2*B1;
double x=-(B1*C2-C1*B2)*1.000000000/k;
double y=(A1*C2-C1*A2)*1.00000000/k;
return x;
}
bool co(Line A,Line B)
{
Point a=A.a; Point b=A.b; Point c=B.a; Point d=B.b;
Vector x,y,xxx,yyy;
x.x=c.x-a.x; x.y=c.y-a.y;
y.x=d.x-a.x; y.y=d.y-a.y;
xxx.x=c.x-b.x; xxx.y=c.y-b.y;
yyy.x=d.x-b.x; yyy.y=d.y-b.y;
if( Cross(x,y)*Cross(xxx,yyy)>eps ) return ;
else return ;
}
double work(Point xx,Point yy)
{
Line qq; qq.a=xx; qq.b=yy; //cout<<xx.x<<" "<<xx.y<<endl;
//cout<<yy.x<<" "<<yy.x<<endl; double ans=-1e18;
for(int i=;i<=n;i++)
{ if(i==)
{
if(co(sg[i],qq)==) return ans;
}
else
{
if(co(sg[i],qq)==) ans=max(ans,make(sg[i],qq));
else
{
if(co(Line(pa[i],pa[i-]),qq)==) ans=max(ans,make(Line(pa[i],pa[i-]),qq));
if(co(Line(pb[i],pb[i-]),qq)==) ans=max(ans,make(Line(pb[i],pb[i-]),qq));
break;
}
}
}
return ans;
}
bool up(Point a,Point b)
{
return a.x<b.x;
}
int main()
{
while()
{
scanf("%d",&n); if(n==) { break; }
for(int i=;i<=n;i++) { scanf("%lf %lf",&pa[i].x,&pa[i].y); } // xia mian dian
sort(pa+,pa++n,up);
for(int i=;i<=n;i++) { pb[i].x=pa[i].x; pb[i].y=pa[i].y+1.0; } // shang mian dian
for(int i=;i<=n;i++) { pa[i].y--; pb[i].y--; } // 下移
for(int i=;i<=n;i++) { sg[i].a=pa[i]; sg[i].b=pb[i]; } // a xiao b shang
double ans=-1e18;
for(int i=;i<=n;i++)
{
for(int j=i+;j<=n;j++) // end
{
ans=max(ans,work(pa[i],pa[j]));
ans=max(ans,work(pa[i],pb[j]));
ans=max(ans,work(pb[i],pa[j]));
ans=max(ans,work(pb[i],pb[j]));
}
//cout<<ans<<endl;
}
if(fabs(ans-pa[n].x)>eps ) printf("%.2f\n",ans);
else printf("Through all the pipe.\n");
}
return ;
}
poj 1039的更多相关文章
- poj 1039 Pipe(叉乘。。。)
题目:http://poj.org/problem?id=1039 题意:有一宽度为1的折线管道,上面顶点为(xi,yi),所对应的下面顶点为(xi,yi-1),假设管道都是不透明的,不反射的,光线从 ...
- POJ - 1039 Pipe(计算几何)
http://poj.org/problem?id=1039 题意 有一宽度为1的折线管道,上面顶点为(xi,yi),所对应的下面顶点为(xi,yi-1),假设管道都是不透明的,不反射的,光线从左边入 ...
- POJ 1039 Pipe【经典线段与直线相交】
链接: http://poj.org/problem?id=1039 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- poj 1039 Pipe (Geometry)
1039 -- Pipe 理解错题意一个晚上._(:з」∠)_ 题意很容易看懂,就是要求你求出从外面射进一根管子的射线,最远可以射到哪里. 正解的做法是,选择上点和下点各一个,然后对于每个折点位置竖直 ...
- nyoj 142, poj 1039 ,hdu 1454 管道问题
http://acm.nyist.net/JudgeOnline/problem.php?pid=142 第一道解析几何问题,比较纠结,主要是几个解析几何的基本操作,包括求两线段的叉积,判断左右方向, ...
- 简单几何(直线与线段相交) POJ 1039 Pipe
题目传送门 题意:一根管道,有光源从入口发射,问光源最远到达的地方. 分析:黑书上的例题,解法是枚举任意的一个上顶点和一个下顶点(优化后),组成直线,如果直线与所有竖直线段有交点,则表示能穿过管道. ...
- POJ 1039问题描述
Description The GX Light Pipeline Company started to prepare bent pipes for the new transgalactic li ...
- POJ 1039 Pipe(直线和线段相交判断,求交点)
Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8280 Accepted: 2483 Description ...
- POJ 1039 Pipe
题意:一根管子,中间有一些拐点,给出拐点的上坐标,下坐标为上坐标的纵坐标减1,管子不能透过光线也不能折射光线,问光线能射到最远的点的横坐标. 解法:光线射到最远处的时候一定最少经过两个拐点,枚举每两个 ...
- poj 1039 Pipe(几何基础)
Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9932 Accepted: 3045 Description ...
随机推荐
- Mac上安装Docker
安装这个东东有两种方法:在线安装和手动安装 在线安装: 打开终端,直接输入brew cask install docker之后回车,执行的过程中会要求输入password(就是你电脑的登录密码),输入 ...
- Selenium 工作原理
Selenium是ThoughtWorks公司研发的一个强大的基于浏览器的开源自动化测试工具,它通常用来编写web应用的自动化测试.早期也即Selenium1.x时期主要使用Selenium RC(S ...
- explor img file
1, get offset # parted bone-debian----4gb.img GNU Parted 3.1 Using /workspace/bone-debian----4gb.img ...
- LoadLibrary 失败的解决
工作中遇到调用Loadlibrary 偶发失败的问题,不是必现,而且这种错误只是在程序初始化的时候出现,初始化成功后当然不会调用,而初始化也不是经常做的动作,所以查找原因起来比较麻烦,调试过程中发现有 ...
- (2018 Multi-University Training Contest 2)Problem G - Naive Operations
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6315 题目大意:告诉你a,b两个数组,a数组初始化为0,b数组告诉你长度和具体值,接下来有q次操作,a ...
- 【转载】IL指令集
转载自:http://www.cnblogs.com/knowledgesea/p/5461040.html 名称 说明 Add 将两个值相加并将结果推送到计算堆栈上. Add.Ovf 将两个整数相加 ...
- Python 在已创建的数据表添加字段报错问题
django.db.utils.IntegrityError: (1062, “Duplicate entry ’1234567891011’ for key_’dingdanid’”) 这个错误是之 ...
- json格式字符串用Uncaught SyntaxError: Unexpected token ' Uncaught SyntaxError: Unexpected number
Unexpected number(index)的错误用的json字符串如 var jsonStr = "{1:'北京note备注信息',2:'上海note备注信息',3:'广东note备注 ...
- VFS 上传文件到sftp 报错 包含中文路径 或者中文文件名称
之前用Apache commons-vfs工具进行ftp操作(FTP服务器是 FileZilla Server) 上传本地文件 到 ftp服务器上,如果文件名称 包含 中文 报错 org.apache ...
- FINS/TCP_OMRON(1)
使用FINS/ TCP与欧姆龙PLC沟通 可参考下列教学 using System.Net; using System.Net.Sockets; 上面必须使用; IPAddress ipAddr = ...