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 }
View Code

posted @ 2014-07-24 20:13  chenjunjie1994  阅读(206)  评论(0编辑  收藏  举报