POJ 1269 Intersecting Lines(计算几何)
来源:互联网 发布:熹妃传厨艺大赛软件 编辑:程序博客网 时间:2024/05/18 16:54
Intersecting Lines
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 14873 Accepted: 6553
Description
We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection because they are parallel, 2) intersect in a line because they are on top of one another (i.e. they are the same line), 3) intersect in a point. In this problem you will use your algebraic knowledge to create a program that determines how and where two lines intersect.
Your program will repeatedly read in four points that define two lines in the x-y plane and determine how and where the lines intersect. All numbers required by this problem will be reasonable, say between -1000 and 1000.
Your program will repeatedly read in four points that define two lines in the x-y plane and determine how and where the lines intersect. All numbers required by this problem will be reasonable, say between -1000 and 1000.
Input
The first line contains an integer N between 1 and 10 describing how many pairs of lines are represented. The next N lines will each contain eight integers. These integers represent the coordinates of four points on the plane in the order x1y1x2y2x3y3x4y4. Thus each of these input lines represents two lines on the plane: the line through (x1,y1) and (x2,y2) and the line through (x3,y3) and (x4,y4). The point (x1,y1) is always distinct from (x2,y2). Likewise with (x3,y3) and (x4,y4).
Output
There should be N+2 lines of output. The first line of output should read INTERSECTING LINES OUTPUT. There will then be one line of output for each pair of planar lines represented by a line of input, describing how the lines intersect: none, line, or point. If the intersection is a point then your program should output the x and y coordinates of the point, correct to two decimal places. The final line of output should read "END OF OUTPUT".
Sample Input
50 0 4 4 0 4 4 05 0 7 6 1 0 2 35 0 7 6 3 -6 4 -32 0 2 27 1 5 18 50 3 4 0 1 2 2 5
Sample Output
INTERSECTING LINES OUTPUTPOINT 2.00 2.00NONELINEPOINT 2.00 5.00POINT 1.07 2.20END OF OUTPUT
Source
Mid-Atlantic 1996
题意:判断两条直线的关系
思路:求直线方程y=kx+b根据k,b的关系判断直线的关系,注意斜率不存在的情况
#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;int main(){double x[10],y[10],k1,k2,b1,b2,k,b,X,Y;int t,i,j;scanf("%d",&t);printf("INTERSECTING LINES OUTPUT\n");while(t--){for(i=1;i<=4;i++)scanf("%lf%lf",&x[i],&y[i]);if(x[1]==x[2]&&x[3]==x[4])//l1,l2斜率都为0 {if(x[1]==x[3]) printf("LINE\n");else printf("NONE\n");}else if(x[1]==x[2]&&x[3]!=x[4])//l1斜率为0,l2斜率不为0 {k=(y[4]-y[3])/(x[4]-x[3]);b=y[4]-k*x[4];printf("POINT %.2lf %.2lf\n",x[1],k*x[1]+b);}else if(x[1]!=x[2]&&x[3]==x[4])//l1斜率不为0,l2斜率为0 {k=(y[2]-y[1])/(x[2]-x[1]);b=y[1]-k*x[1];printf("POINT %.2lf %.2lf\n",x[3],k*x[3]+b);}else if(x[1]!=x[2]&&x[3]!=x[4])//斜率都不为0 {k1=(y[2]-y[1])/(x[2]-x[1]);b1=y[1]-k1*x[1];k2=(y[4]-y[3])/(x[4]-x[3]);b2=y[4]-k2*x[4];//printf("k1=%.2lf k2=%.2lf %.2lf %.2lf\n",k1,k2,b1,b2);if(k1==k2&&b1==b2){printf("LINE\n");}else if(k1==k2&&b1!=b2){printf("NONE\n");}else {X=(b2-b1)/(k1-k2);Y=k1*X+b1;printf("POINT %.2lf %.2lf\n",X,Y);}}}printf("END OF OUTPUT\n");return 0;}
0 0
- poj 1269 Intersecting Lines(计算几何)
- POJ 1269 Intersecting Lines(计算几何)
- poj 1269 Intersecting Lines(计算几何)
- POJ 1269 Intersecting Lines(计算几何)
- POJ 1269 Intersecting Lines --计算几何
- POJ 1269 Intersecting Lines(计算几何)
- poj 1269 Intersecting Lines(计算几何)
- poj 1269 Intersecting Lines 计算几何
- POJ 1269 Intersecting Lines 简单计算几何
- POJ 1269 Intersecting Lines 计算几何基础
- poj 1269 Intersecting Lines(计算几何:线段相交)
- 1269---Intersecting Lines---计算几何
- Intersecting Lines (计算几何)
- POJ 1269 Intersecting Lines(计算几何 求交点)
- poj 1269 Intersecting Lines 计算几何 直线求交点
- POJ 1269 Intersecting Lines(简单计算几何,判断直线的关系)
- Intersecting Lines(计算几何基础)
- [POJ1269]Intersecting Lines(计算几何)
- java 判断文件是否图片
- 利用GDI+在问from绘制验证码
- eclipse生成可执行jar包 ,带第三方jar(转)
- QNearFieldManager类Detailed Description英文翻译:
- POI 读写 Excel
- POJ 1269 Intersecting Lines(计算几何)
- oracle minus 不包含
- Cookie/Session机制详解
- Eclipse构建Maven项目
- Eclipse+Maven创建webapp项目(转)
- JavaScript中的ReferenceError和TypeError两种错误的区别
- 测试大神的经验之谈
- ORA-01034: ORACLE not available ORA-27101
- Oracle归档日志满了导致无法启动ora-03113