poj1039 几何
来源:互联网 发布:jquery.color.js 下载 编辑:程序博客网 时间:2024/05/16 12:47
链接:http://poj.org/problem?id=1039
Pipe
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 9513 Accepted: 2887
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.
Source
Central Europe 1995
总结下线段和直线的关系之类的
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<vector>#include<queue>#include<set>#include<map>#include<stack>#include<cmath>#define mst(ss,b) memset((ss),(b),sizeof(ss))#define maxn 0x3f3f3f3fusing namespace std;int n;struct point { double x,y; point(double x=0,double y=0):x(x),y(y) {}} s[22],p[22];const double eps=1e-8;typedef point vec;vec operator - (point a,point b) { return vec(a.x-b.x,a.y-b.y);}vec operator + (point a,point b) { return vec(a.x+b.x,a.y+b.y);}vec operator * (point a,double t) { return vec(a.x*t,a.y*t);}int dcmp(double x) { if(fabs(x)<=eps) return 0; else return x<0?-1:1;}double cross(vec a,vec b) { ///叉积 当前向量逆时针180度为正,顺时针180度为负 return a.x*b.y-a.y*b.x; ///叉积 绝对值也是有向面积}bool pd(point a,point b,point c,point d) { double c1=cross(b-a,c-a); double c2=cross(b-a,d-a); /// c1*c2<=0 表示cd在ab左右,并不能表示ab在cd左右 double c3=cross(d-c,a-c); double c4=cross(d-c,b-c); /// c3*c4<=0 表示ab在cd左右,并不能表示cd在ab左右 return dcmp(c1)*dcmp(c2)<=0; /// cd在ab左右才返回true;}double intersection(point a,point b,point c,point d){ double c1=cross(b-a,c-a); double c2=cross(b-a,d-a); if(dcmp(c1)*dcmp(c2)<0){ /// x=(c2*c.x-c1*d.x)/(c2-c1); /// y=(c2*c.y-c1*d.y)/(c2-c1); 求直线ab与线段cd的交点坐标(前提是cd在ab的左右) return (c2*c.x-c1*d.x)/(c2-c1); } if(dcmp(c1)*dcmp(c2)==0){ if(dcmp(c1)==0) return c.x; else return d.x; } return -maxn*1.0;}int main() { while(scanf("%d",&n)!=EOF) { if(n==0) break; for(int i=0; i<n; i++) { scanf("%lf%lf",&s[i].x,&s[i].y); p[i].x=s[i].x; p[i].y=s[i].y-1; } double ans=-maxn*1.0; int flag=0,k; for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { if(i!=j) { for(k=0; k<n; k++) { if(!pd(s[i],p[j],s[k],p[k])) { break; } } if(k>=n) { flag=1; break; } else if(k>=max(i,j)){ double temp=intersection(s[i],p[j],s[k],s[k-1]); ans=max(temp,ans); temp=intersection(s[i],p[j],p[k],p[k-1]); ans=max(ans,temp); } } } if(flag) break; } if(flag) printf("Through all the pipe.\n"); else printf("%.2f\n",ans); } return 0;}
0 0
- poj1039 几何
- poj1039---计算几何
- poj1039 Pipe (计算几何)
- poj1039 pipe 计算几何
- poj1039 计算几何加枚举
- poj1039(计算几何)线段相交
- POJ1039——计算几何
- poj1039--Pipe(计算几何)
- poj1039 计算几何-交点,叉积
- JOJ1076 && POJ1039 Pipe 经典计算几何
- poj1039 Pipe(计算几何叉积求交点)
- poj1039
- POJ1039 Pipe
- POJ1039-Pipe
- poj1039 Pipe
- poj1039 Pipe
- Pipe(poj1039线段相交)
- POJ1039 激光照管子
- UIView的alpha、hidden和opaque属性之间的关系和区别
- C#中的override和new关键字
- Bash下的变量配置规则
- 高级Java程序员值得拥有的10本书
- CSU 1527 - Bounty Hunter(DP‘双调旅行商问题)
- poj1039 几何
- 我为什么要学习Linux?
- 将01矩阵转化为bitmap文件
- 5-14 数据结构啊poi Q.购票
- C++中关于[]静态数组和new分配的动态数组的区别分析
- 微软将会在它的搜索结果中推送移动端友好的网站
- 键值编码KVC
- k-means java实现
- 怎样花两年时间去面试一个人