forked from zhuli19901106/poj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
POJ1269(AC).cpp
68 lines (62 loc) · 1.38 KB
/
POJ1269(AC).cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
using namespace std;
int p[4][2];
int a1, b1, c1;
int a2, b2, c2;
int main()
{
int n, ni;
int i;
while(scanf("%d", &n) == 1){
printf("INTERSECTING LINES OUTPUT\n");
for(ni = 0; ni < n; ++ni){
for(i = 0; i < 4; ++i){
scanf("%d%d", &p[i][0], &p[i][1]);
}
b1 = -(p[1][0] - p[0][0]);
a1 = +(p[1][1] - p[0][1]);
c1 = - a1 * p[0][0] - b1 * p[0][1];
b2 = -(p[3][0] - p[2][0]);
a2 = +(p[3][1] - p[2][1]);
c2 = - a2 * p[2][0] - b2 * p[2][1];
if(!a1 && b1){
if(!a2 && b2){
if(b1 * c2 == b2 * c1){
printf("LINE\n");
}else{
printf("NONE\n");
}
continue;
}else if(a2 && !b2){
printf("POINT %.2f %.2f\n", -1.0 * c2 / a2, -1.0 * c1 / b1);
continue;
}
}else if(a1 && !b1){
if(!a2 && b2){
printf("POINT %.2f %.2f\n", -1.0 * c1 / a1, -1.0 * c2 / b2);
continue;
}else if(a2 && !b2){
if(a1 * c2 == a2 * c1){
printf("LINE\n");
}else{
printf("NONE\n");
}
continue;
}
}
if(a1 * b2 == a2 * b1){
if(a1 * c2 == a2 * c1 && b1 * c2 == b2 * c1){
printf("LINE\n");
}else{
printf("NONE\n");
}
}else{
printf("POINT %.2f %.2f\n", 1.0 * (c2 * b1 - c1 * b2) / (a1 * b2 - a2 * b1), 1.0 * (c2 * a1 - c1 * a2) / (b1 * a2 - b2 * a1));
}
}
printf("END OF OUTPUT\n");
}
return 0;
}