我是靠谱客的博主 笑点低人生,最近开发中收集的这篇文章主要介绍hdoj Pipe&&南阳oj管道问题&&poj1039(计算几何问题...枚举)Pipe,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
Pipe
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 240 Accepted Submission(s): 99
Problem 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
4 0 1 2 2 4 1 6 4 6 0 1 2 -0.6 5 -4.45 7 -5.57 12 -10.8 17 -16.55 0
Sample Output
4.67 Through all the pipe.
题解:中间找x点坐标还没理解,中间判断相交,以及与上下管道相交处理的很巧妙;
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int INF=0x3f3f3f3f; struct Node{ double x,y; }; Node point[30][2]; double chaji(Node a,Node b,Node c){ return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x); } double is_intersection(Node a,Node b,Node c,Node d){ return chaji(a,b,c)*chaji(a,b,d); } double area(Node a,Node b,Node c){ double ab,bc,ac; ab=sqrt(1.0*pow(b.x-a.x,2)+pow(b.y-a.y,2)); ac=sqrt(1.0*pow(c.x-a.x,2)+pow(c.y-a.y,2)); bc=sqrt(1.0*pow(c.x-b.x,2)+pow(c.y-b.y,2)); double p=(ab+bc+ac)/2.0;// /2 return sqrt(p*(p-ac)*(p-ab)*(p-bc)); } double getx(Node a,Node b,Node c,Node d){ double s1=area(a,b,c),s2=area(a,b,d); return (s1*d.x+s2*c.x)/(s1+s2);//找x坐标,没理解太清; } int main(){ int n; while(scanf("%d",&n),n){ for(int i=0;i<n;i++){ scanf("%lf%lf",&point[i][0].x,&point[i][0].y); point[i][1].x=point[i][0].x; point[i][1].y=point[i][0].y-1; } Node s_1=point[0][0],s_2=point[0][1],a,b; double ans=-INF; int flot=0; for(int q=0;q<n;q++){ for(int w=0;w<2;w++){ a=point[q][w]; for(int e=q+1;e<n;e++){ for(int r=0;r<2;r++){ b=point[e][r]; if(is_intersection(a,b,s_1,s_2)<=0){ int t; for(t=1;t<n;t++){ if(is_intersection(a,b,point[t][0],point[t][1])>0){ double x; if(chaji(a,b,point[t][0])>0) x=getx(a,b,point[t-1][1],point[t][1]); else x=getx(a,b,point[t-1][0],point[t][0]); ans=max(ans,x); break; } } if(t==n)flot=1; } } } } } if(flot)puts("Through all the pipe."); else printf("%.2fn",ans); } return 0; }
转载于:https://www.cnblogs.com/handsomecui/p/4931606.html
最后
以上就是笑点低人生为你收集整理的hdoj Pipe&&南阳oj管道问题&&poj1039(计算几何问题...枚举)Pipe的全部内容,希望文章能够帮你解决hdoj Pipe&&南阳oj管道问题&&poj1039(计算几何问题...枚举)Pipe所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复