POJ 1269

中学的 又用上了。

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4
 5 using namespace std;
 6
 7 int x1,y1,x2,y2,x3,y3,x4,y4;
 8 double k1,k2,k3,d1,d2;
 9 double x,y;
10
11 bool asure(){
12     if(x1==x2||x3==x4){
13         if(x1==x2&&x3==x4&&x1==x3)
14         printf("LINE\n");
15         else if(x1==x2&&x3==x4&&x1!=x3)
16         printf("NONE\n");
17         else{
18             if(x1==x2){
19                 k2=(y3-y4)*1.0/(x3-x4)*1.0;
20                 d2=y3*1.0-k2*x3;
21                 x=x1;
22                 y=k2*x+d2;
23             }
24             else {
25                 k1=(y1-y2)*1.0/(x1-x2)*1.0;
26                 d1=y1*1.0-k1*x1;
27                 x=x3;
28                 y=k1*x+d1;
29             }
30             printf("POINT %0.2lf %0.2lf\n",x,y);
31         }
32         return true;
33     }
34     return false;
35 }
36
37
38 int main(){
39     int T;
40     while(scanf("%d",&T)!=EOF){
41         printf("INTERSECTING LINES OUTPUT\n");
42         while(T--){
43             scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
44             if(asure()) continue;
45             k1=(y1-y2)*1.0/(x1-x2)*1.0; k2=(y3-y4)*1.0/(x3-x4)*1.0;
46             if(k1==k2){
47                 k3=(y2-y3)*1.0/(x2-x3)*1.0;
48                 if(k1==k3){
49                     printf("LINE\n");
50                 }
51                 else printf("NONE\n");
52                 continue;
53             }
54             else {
55                 d1=y1*1.0-k1*x1;
56                 d2=y3*1.0-k2*x3;
57                 y=(k2*d1-k1*d2)/(k2-k1);
58                 x=(y-d1)*1.0/k1;
59                 printf("POINT %0.2lf %0.2lf\n",x,y);
60             }
61         }
62         printf("END OF OUTPUT\n");
63     }
64     return 0;
65 }

POJ 1269

时间: 2024-11-05 11:06:51

POJ 1269的相关文章

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

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 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10967   Accepted: 4930 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

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 计算几何

1 /** 2 判断直线位置关系 3 **/ 4 #include <iostream> 5 #include <cmath> 6 #include <cstdio> 7 using namespace std; 8 struct point { 9 double x,y; 10 point(double x=0,double y=0):x(x),y(y){} 11 }; 12 13 typedef point Vector; 14 15 Vector operator

直线相交 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

判断两条直线的位置关系 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 直线相交判断

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