poj 1269 Intersecting Lines 直线交点
来源:互联网 发布:海马苹果助手mac 编辑:程序博客网 时间:2024/06/05 06:51
Intersecting Lines
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 8222 Accepted: 3746
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
---------
求直线交点
---------
#include<vector>#include<list>#include<map>#include<set>#include<deque>#include<queue>#include<stack>#include<bitset>#include<algorithm>#include<functional>#include<numeric>#include<utility>#include<iostream>#include<sstream>#include<iomanip>#include<cstdio>#include<cmath>#include<cstdlib>#include<cctype>#include<string>#include<cstring>#include<cstdio>#include<cmath>#include<cstdlib>#include<ctime>#include<climits>#include<complex>#define mp make_pair#define pb push_backusing namespace std;const double eps=1e-8;const double pi=acos(-1.0);const double inf=1e20;const int maxp=1111;int dblcmp(double d){ if (fabs(d)<eps)return 0; return d>eps?1:-1;}inline double sqr(double x){return x*x;}struct point{ double x,y; point(){} point(double _x,double _y): x(_x),y(_y){}; void input() { scanf("%lf%lf",&x,&y); } void output() { printf("%.2f %.2f\n",x,y); } bool operator==(point a)const { return dblcmp(a.x-x)==0&&dblcmp(a.y-y)==0; } bool operator<(point a)const { return dblcmp(a.x-x)==0?dblcmp(y-a.y)<0:x<a.x; } double distance(point p) { return hypot(x-p.x,y-p.y); } point add(point p) { return point(x+p.x,y+p.y); } point sub(point p) { return point(x-p.x,y-p.y); } point mul(double b) { return point(x*b,y*b); } point div(double b) { return point(x/b,y/b); } double dot(point p) { return x*p.x+y*p.y; } double det(point p) { return x*p.y-y*p.x; } double len() { return hypot(x,y); } double len2() { return x*x+y*y; }};struct line{ point a,b; line(){} line(point _a,point _b) { a=_a; b=_b; } bool operator==(line v) { return (a==v.a)&&(b==v.b); } void input() { a.input(); b.input(); } void adjust() { if (b<a)swap(a,b); } double length() { return a.distance(b); } //点和线段关系 //1 在逆时针 //2 在顺时针 //3 平行 int relation(point p) { int c=dblcmp(p.sub(a).det(b.sub(a))); if (c<0)return 1; if (c>0)return 2; return 3; } bool parallel(line v) { return dblcmp(b.sub(a).det(v.b.sub(v.a)))==0; } int linecrossline(line v) { if ((*this).parallel(v)) { return v.relation(a)==3; } return 2; } point crosspoint(line v) { double a1=v.b.sub(v.a).det(a.sub(v.a)); double a2=v.b.sub(v.a).det(b.sub(v.a)); return point((a.x*a2-b.x*a1)/(a2-a1),(a.y*a2-b.y*a1)/(a2-a1)); }};int main(){ int n; line a,b; while (~scanf("%d",&n)) { puts("INTERSECTING LINES OUTPUT"); for (int i=1;i<=n;i++) { a.input(); b.input(); int ret=a.linecrossline(b); if (ret==0) { puts("NONE"); } if (ret==1) { puts("LINE"); } if (ret==2) { point ans=a.crosspoint(b); printf("POINT "); ans.output(); } } puts("END OF OUTPUT"); } return 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(计算几何 直线交点 点在直线上 直线平行)
- POJ 1269 Intersecting Lines 判断直线关系(相交(求交点),重合,平行)
- poj 1269 Intersecting Lines(直线相交判断,求相交交点)
- POJ 1269 Intersecting Lines(直线相交?平行?重合?,求交点)
- poj 1269Intersecting Lines (直线相交判断,求相交交点)
- poj 1269 Intersecting Lines--直线相交
- POJ 1269 Intersecting Lines 直线交
- poj 1269 Intersecting Lines 直线位置关系
- 新手学c++
- poj 2007 Scrambled Polygon 极角排序
- 牛顿定律
- Response的sendRedirect实现JSF内的URL重定向
- 【91xcz】假如win7系统回收站桌面图标被删除那么该如何解决
- poj 1269 Intersecting Lines 直线交点
- 贡献30本经典Linux学习和开发教程和资料,都是pdf完整版的
- effecitve c++之const
- Gson操作
- Linux文件夹的操作
- Mapserver ms4w 不能正常运行
- String_Equals_小知识点
- Android创建隐藏文件或者文件夹,并对其读写操作
- Android中如何获取手机屏幕大小 .