Pipe - POJ 1039 几何
来源:互联网 发布:图像算法工程师前途 编辑:程序博客网 时间:2024/04/30 23:00
Pipe
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 9646 Accepted: 2940
Description
The GX Light Pipeline Company started to prepare bent pipes for the new transgalactic light pipeline. During the design phase of the new pipe shape the company ran into the problem of determining how far the light can reach inside each component of the pipe. Note that the material which the pipe is made from is not transparent and not light reflecting.
Each pipe component consists of many straight pipes connected tightly together. For the programming purposes, the company developed the description of each component as a sequence of points [x1; y1], [x2; y2], . . ., [xn; yn], where x1 < x2 < . . . xn . These are the upper points of the pipe contour. The bottom points of the pipe contour consist of points with y-coordinate decreased by 1. To each upper point [xi; yi] there is a corresponding bottom point [xi; (yi)-1] (see picture above). The company wants to find, for each pipe component, the point with maximal x-coordinate that the light will reach. The light is emitted by a segment source with endpoints [x1; (y1)-1] and [x1; y1] (endpoints are emitting light too). Assume that the light is not bent at the pipe bent points and the bent points do not stop the light beam.
Each pipe component consists of many straight pipes connected tightly together. For the programming purposes, the company developed the description of each component as a sequence of points [x1; y1], [x2; y2], . . ., [xn; yn], where x1 < x2 < . . . xn . These are the upper points of the pipe contour. The bottom points of the pipe contour consist of points with y-coordinate decreased by 1. To each upper point [xi; yi] there is a corresponding bottom point [xi; (yi)-1] (see picture above). The company wants to find, for each pipe component, the point with maximal x-coordinate that the light will reach. The light is emitted by a segment source with endpoints [x1; (y1)-1] and [x1; y1] (endpoints are emitting light too). Assume that the light is not bent at the pipe bent points and the bent points do not stop the light beam.
Input
The input file contains several blocks each describing one pipe component. Each block starts with the number of bent points 2 <= n <= 20 on separate line. Each of the next n lines contains a pair of real values xi, yi separated by space. The last block is denoted with n = 0.
Output
The output file contains lines corresponding to blocks in input file. To each block in the input file there is one line in the output file. Each such line contains either a real value, written with precision of two decimal places, or the message Through all the pipe.. The real value is the desired maximal x-coordinate of the point where the light can reach from the source for corresponding pipe component. If this value equals to xn, then the message Through all the pipe. will appear in the output file.
Sample Input
40 12 24 16 460 12 -0.65 -4.457 -5.5712 -10.817 -16.550
Sample Output
4.67Through all the pipe.
题意:给你一个管道,让你从最左边射进光线,问光线最远达到的x坐标是多少,或者可以死贯穿管道。
思路:枚举管道拐角的上界和下届,组成一个直线,然后判断这条直线是否能达到左边界以及最远能达到的x坐标。
AC代码如下:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>using namespace std;typedef long long ll;struct Point{ double x,y; Point(double x=0,double y=0):x(x),y(y){}};double PI=acos(-1.0),eps=1e-8;typedef Point Vector;Vector operator + (Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}Vector operator - (Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);}Vector operator * (Vector A,double p){return Vector(A.x*p,A.y*p);}Vector operator / (Vector A,double p){return Vector(A.x/p,A.y/p);}int dcmp(double x){return (x>eps)-(x<-eps);}double Cross(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 Length(Vector A){return sqrt(Dot(A,A));}double Angle(Vector A,Vector B){return acos(Dot(A,B)/Length(A)/Length(B));}bool Intersection(Point a1,Point a2,Point b1,Point b2,Point c1,Point c2){ double d1=Cross(c1-c2,a1-c2); double d2=Cross(c1-c2,a2-c2); double d3=Cross(c1-c2,b1-c2); double d4=Cross(c1-c2,b2-c2); if(dcmp(d1)*dcmp(d2)<0 || dcmp(d3)*dcmp(d4)<0) return 1; if(dcmp(d1)<=0 && dcmp(d2)<=0 && dcmp(d3)<=0 && dcmp(d4)<=0) return 1; if(dcmp(d1)>=0 && dcmp(d2)>=0 && dcmp(d3)>=0 && dcmp(d4)>=0) return 1; return 0;}bool SegmentIntersection(Point a1,Point a2,Point b1,Point b2){ double c1=Cross(b1-b2,a1-b2); double c2=Cross(b1-b2,a2-b2); return dcmp(c1)*dcmp(c2)<=0;}void jiaodian(Point a1,Point a2,Point b1,Point b2,Point &as){ double s1=Cross(a1-b1,b2-b1); double s2=Cross(a2-b1,b2-b1); as=(a2*s1-a1*s2)/(s1-s2);}int T,t,n,m,INF=1e9;double ans;Point p[25][2];void solve(Point a,Point b){ int i,j,k; double ret; Point c; for(i=1;i<n;i++) if(Intersection(p[i][0],p[i+1][0],p[i][1],p[i+1][1],a,b)) break; if(i==n) { ans=INF; return; } if(p[i][0].x<a.x) return; if(SegmentIntersection(p[i][0],p[i+1][0],a,b)) { jiaodian(p[i][0],p[i+1][0],a,b,c); ans=max(ans,c.x); } if(SegmentIntersection(p[i][1],p[i+1][1],a,b)) { jiaodian(p[i][1],p[i+1][1],a,b,c); ans=max(ans,c.x); }}int main(){ int i,j,k; while(~scanf("%d",&n) && n>0) { for(i=1;i<=n;i++) { scanf("%lf%lf",&p[i][0].x,&p[i][0].y); p[i][1].x=p[i][0].x; p[i][1].y=p[i][0].y-1; } ans=-INF; for(i=1;i<=n;i++) for(j=i+1;j<=n;j++) { solve(p[i][0],p[j][1]); solve(p[i][1],p[j][0]); } if(dcmp(ans-INF)==0) printf("Through all the pipe.\n"); else printf("%.2f\n",ans); }}
0 0
- Pipe - POJ 1039 几何
- poj 1039 Pipe (计算几何)
- POJ 1039 Pipe (计算几何)
- POJ 1039:Pipe 计算几何
- poj 1039 Pipe 计算几何
- POJ 1039 Pipe <计算几何>
- POJ 1039 Pipe 计算几何题目。。
- POJ-1039-Pipe-枚举(计算几何)
- POJ 1039 Pipe【计算几何+直线相交】
- POJ 1039 Pipe (计算几何、思维、线段相交)
- POJ 1039-Pipe(计算几何-线段相交、求交点)
- hdoj 1454&&poj 1039 Pipe 1454 (数学计算几何) 枚举
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- 用redis实现微博关注关系
- Groovy WEB网站中文乱码问题解决方案-过滤器
- OptionMenu布局问题
- 采用模态对话框交互时的变量传递
- POJ 2186 -- Popular Cows【强连通分支 && Tarjan缩点】
- Pipe - POJ 1039 几何
- android.os.NetworkOnMainThreadException(未开启子线程)
- laravel-soap 使用
- 求无向图割顶,桥,删除点后增加的连通块数
- 分分钟学会写简单的图片加载框架
- iframe图片上传
- 内容垂直、水平居中
- ssoj1933墨墨的等式(equ)
- wampserver localhost 403