标签:des style blog color os io strong for
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 10967 | Accepted: 4930 |
Description
Input
Output
Sample Input
5 0 0 4 4 0 4 4 0 5 0 7 6 1 0 2 3 5 0 7 6 3 -6 4 -3 2 0 2 27 1 5 18 5 0 3 4 0 1 2 2 5
Sample Output
INTERSECTING LINES OUTPUT POINT 2.00 2.00 NONE LINE POINT 2.00 5.00 POINT 1.07 2.20 END OF OUTPUT
题意:
给两条线,求他们之间的关系。关系有3种:相交、共线、平行。
思路:
模拟手算就行了,注意直线可能没有斜率,用G++提交时用%.2f而不能用%.2lf,否则判错。
代码:
1 #include <iostream> 2 #include <string> 3 #include <map> 4 #include <stdio.h> 5 #include <math.h> 6 using namespace std; 7 #define pi acos(-1) 8 9 10 main() 11 { 12 int t, t1; 13 double x1, y1, x2, y2, x3, y3, x4, y4; 14 double k1, b1, k2, b2, x, y; 15 cin>>t; 16 t1=t; 17 while(t--){ 18 if(t1==t+1){ 19 printf("INTERSECTING LINES OUTPUT\n"); 20 } 21 scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4); 22 if(x1==x2&&x3==x4){ //当两条线都没有斜率时 23 if(x1==x3) printf("LINE\n"); 24 else printf("NONE\n"); 25 } 26 else if(x1==x2){ //第一条线没斜率 27 k1=(y4-y3)/(x4-x3); 28 b1=y4-k1*x4; 29 printf("POINT %.2f %.2f\n",x1,k1*x1+b1); 30 } 31 else if(x3==x4){ //第二条线没斜率 32 k1=(y2-y1)/(x2-x1); 33 b1=y2-k1*x1; 34 printf("POINT %.2f %.2f\n",x3,k1*x3+b1); 35 } 36 else{ //都有斜率 37 k1=(y2-y1)/(x2-x1); 38 k2=(y4-y3)/(x4-x3); 39 b1=y2-k1*x2; 40 b2=y4-k2*x4; 41 if(k1==k2&&b1==b2){ 42 printf("LINE\n"); 43 } 44 else if(k1==k2){ 45 printf("NONE\n"); 46 } 47 else{ 48 x=(b1-b2)/(k2-k1); 49 y=k1*x+b1; 50 printf("POINT %.2f %.2f\n",x,y); 51 } 52 } 53 if(t==0) printf("END OF OUTPUT\n"); 54 } 55 }
标签:des style blog color os io strong for
原文地址:http://www.cnblogs.com/qq1012662902/p/3920256.html