http://poj.org/problem?id=1269
Intersecting Lines
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 9061 Accepted: 4066
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.
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
5
0 0 4 4 0 4 4 0
5 0 7 6 1 0 2 3
5 0 7 6 3 -6 4 -3
2 0 2 27 1 5 18 5
0 3 4 0 1 2 2 5
Sample Output
INTERSECTING LINES OUTPUT
POINT 2.00 2.00
NONE
LINE
POINT 2.00 5.00
POINT 1.07 2.20
END OF OUTPUT
Source
Mid-Atlantic 1996
解析:
题意:
给出n对直线,判断每对直线是否相交,平行,重叠,如果相加就要求出交点
思路:
根据所给条件求出直线的解析式:
line1: y=k1*x+b1;
line2: y=k2*x+b2;
交点为(X,Y)
X=(b2-b1)/(k1-k2);
Y=k2*X+b2;
注意:判断的时候要根据斜率直线是否存在分类讨论
184 0MS C++ 1472B
*/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <iostream>
using namespace std;
const int maxn=20;
struct line
{
double x1,x2;
double y1,y2;
}lin[maxn][2];
void solve(line L1,line L2)
{
double k1,k2,a1,a2,b1,b2,c1,c2,x,y;
a1=L1.x1-L1.x2;
a2=L2.x1-L2.x2;
b1=L1.y1-L1.y2;
b2=L2.y1-L2.y2;
if(a1==0||a2==0)//当斜率不存在时
{
if(a1==0&&a2==0)
{
if(L1.x1==L2.x1)//重叠
printf("LINE\n");
else
printf("NONE\n");//平行
}
if(a1==0&&a2!=0)
{
x=L1.x1;
k2=b2/a2;
c2=L2.y2-k2*L2.x2;
y=k2*x+c2;
printf("POINT %.2lf %.2lf\n",x,y);
}
if(a2==0&&a1!=0)
{
x=L2.x2;
k1=b1/a1;
c1=L1.y1-k1*L1.x1;
y=k1*x+c1;
printf("POINT %.2lf %.2lf\n",x,y);
}
}
else
{
k1=b1/a1;
k2=b2/a2;
c1=L1.y1-k1*L1.x1;
c2=L2.y2-k2*L2.x2;
if(k1==k2)
{
if(c1==c2)
printf("LINE\n");
else
printf("NONE\n");
}
else
{
x=(c2-c1)/(k1-k2);
y=k1*x+c1;
printf("POINT %.2lf %.2lf\n",x,y);
}
}
}
int main()
{
int n,i,j;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
{
scanf("%lf%lf%lf%lf",&lin[i][0].x1,&lin[i][0].y1,&lin[i][0].x2,&lin[i][0].y2);
scanf("%lf%lf%lf%lf",&lin[i][1].x1,&lin[i][1].y1,&lin[i][1].x2,&lin[i][1].y2);
}
printf("INTERSECTING LINES OUTPUT\n");
for(i=0;i<n;i++)
solve(lin[i][0],lin[i][1]);
printf("END OF OUTPUT\n");
}
return 0;
}

本文概述了AI音视频处理领域的关键技术,包括视频分割、语义识别、自动驾驶、AR、SLAM、物体检测与识别、语音识别变声等,为开发者提供了一个全面的技术视角。
286

被折叠的 条评论
为什么被折叠?



