直线相交 POJ 1269

 1 // 直线相交 POJ 1269
 2
 3 // #include <bits/stdc++.h>
 4 #include <iostream>
 5 #include <cstdio>
 6 #include <cstdlib>
 7 #include <algorithm>
 8 #include <math.h>
 9 using namespace std;
10 #define LL long long
11 typedef pair<int,int> pii;
12 const double inf = 123456789012345.0;
13 const LL MOD =100000000LL;
14 const int N =1e4+10;
15 #define clc(a,b) memset(a,b,sizeof(a))
16 const double eps = 1e-8;
17 void fre() {freopen("in.txt","r",stdin);}
18 void freout() {freopen("out.txt","w",stdout);}
19 inline int read() {int x=0,f=1;char ch=getchar();while(ch>‘9‘||ch<‘0‘) {if(ch==‘-‘) f=-1; ch=getchar();}while(ch>=‘0‘&&ch<=‘9‘) {x=x*10+ch-‘0‘;ch=getchar();}return x*f;}
20
21 int sgn(double x){
22     if(fabs(x) < eps)return 0;
23     if(x < 0)return -1;
24     else return 1;
25 }
26 struct Point{
27     double x,y;
28     Point(){}
29     Point(double _x,double _y){
30         x = _x;y = _y;
31     }
32     Point operator -(const Point &b)const{
33         return Point(x - b.x,y - b.y);
34     }
35     double operator ^(const Point &b)const{
36         return x*b.y - y*b.x;
37     }
38     double operator *(const Point &b)const{
39         return x*b.x + y*b.y;
40     }
41 };
42
43 struct Line{
44     Point s,e;
45     Line(){}
46     Line(Point _s,Point _e){
47         s=_s;e=_e;
48     }
49     pair<int,Point> operator & (const Line &b) const{
50         Point res=s;
51         if(sgn((s-e)^(b.s-b.e))==0){
52             if(sgn((s-b.e)^(b.s-b.e))==0)
53                 return make_pair(0,res);
54             else  return make_pair(1,res);
55         }
56         double t=((s-b.s)^(b.s-b.e))/((s-e)^(b.s-b.e));
57         res.x+=(e.x-s.x)*t;
58         res.y+=(e.y-s.y)*t;
59         return make_pair(2,res);
60     }
61 };
62
63 int main(){
64     int T;
65     scanf("%d",&T);
66     double x1,x2,x3,x4,y1,y2,y3,y4;
67     printf("INTERSECTING LINES OUTPUT\n");
68     while(T--){
69         scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
70         Line line1 = Line(Point(x1,y1),Point(x2,y2));
71         Line line2 = Line(Point(x3,y3),Point(x4,y4));
72         pair<int,Point> ans=line1 & line2;
73         if(ans.first==0) printf("LINE\n");
74         else if(ans.first==1) printf("NONE\n");
75         else printf("POINT %.2f %.2f\n",ans.second.x,ans.second.y);
76     }
77     printf("END OF OUTPUT\n");
78     return 0;
79 }
时间: 2024-10-04 13:02:03

直线相交 POJ 1269的相关文章

判断线段和直线相交 POJ 3304

1 // 判断线段和直线相交 POJ 3304 2 // 思路: 3 // 如果存在一条直线和所有线段相交,那么平移该直线一定可以经过线段上任意两个点,并且和所有线段相交. 4 5 #include <cstdio> 6 #include <cstring> 7 #include <iostream> 8 #include <algorithm> 9 #include <map> 10 #include <set> 11 #inclu

简单几何(直线位置) POJ 1269 Intersecting Lines

题目传送门 题意:判断两条直线的位置关系,共线或平行或相交 分析:先判断平行还是共线,最后就是相交.平行用叉积判断向量,共线的话也用叉积判断点,相交求交点 /************************************************ * Author :Running_Time * Created Time :2015/10/24 星期六 09:08:55 * File Name :POJ_1269.cpp *********************************

POJ 1269 Intersecting Lines(判断直线相交)

题目地址:POJ 1269 直接套模板就可以了...实在不想自己写模板了...写的又臭又长....不过这题需要注意的是要先判断是否有直线垂直X轴的情况. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h>

POJ 1269 Intersecting Lines 直线相交判断

D - Intersecting Lines Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1269 Appoint description:  System Crawler  (2016-05-08) Description We all know that a pair of distinct points on a plane d

POJ 1269 Intersecting Lines(线段相交,水题)

Intersecting Lines 大意:给你两条直线的坐标,判断两条直线是否共线.平行.相交,若相交,求出交点. 思路:线段相交判断.求交点的水题,没什么好说的. struct Point{ double x, y; } ; struct Line{ Point a, b; } A, B; double xmult(Point p1, Point p2, Point p) { return (p1.x-p.x)*(p2.y-p.y)-(p1.y-p.y)*(p2.x-p.x); } bool

判断两条直线的位置关系 POJ 1269 Intersecting Lines

两条直线可能有三种关系:1.共线     2.平行(不包括共线)    3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, p2, p3, p4,直线L1,L2分别穿过前两个和后两个点.来判断直线L1和L2的关系 这三种关系一个一个来看: 1. 共线. 如果两条直线共线的话,那么另外一条直线上的点一定在这一条直线上.所以p3在p1p2上,所以用get_direction(p1, p2, p3)来判断p3相对于p1p2的关

poj 1269 Intersecting Lines(判相交交点与平行)

http://poj.org/problem?id=1269 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10379   Accepted: 4651 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

POJ 1269 Intersecting Lines (判断直线位置关系)

题目链接:POJ 1269 Problem 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 becau

poj 1269 线段与线段相交

Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13605   Accepted: 6049 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