fork download
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <cstdio>
  6. #include <math.h>
  7.  
  8. #define pi 3.141592653589793
  9. using namespace std;
  10. /*已知两点(x1,y1)(x2,y2)求直线方程(ax+by+c=0) :
  11. 解得:a=y1-y2,b=x2-x1,c=x1*y2-x2*y1;*/
  12. //x=(c1-b1c1+b1c2)/(a1b1-a2b1-a1)
  13. //y=-[a1*(c1-c1b1+b1c2)/(a1b1-a2b1-a1)+c1]/b1
  14. int main(){
  15. int n,i=0;
  16. cin>>n;
  17. double x1,y1,x2,y2,x3,y3,x4,y4;
  18. cout<<"INTERSECTING LINES OUTPUT"<<endl;
  19. for (;i<n;i++)
  20. {
  21. cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
  22. double a1=y1-y2,b1=x2-x1,c1=x1*y2-x2*y1;
  23. double a2=y3-y4,b2=x4-x3,c2=x3*y4-x4*y3;
  24. // cout<<"First line:"<<a1<<"x"<<"+"<<b1<<"y+"<<c1<<"=0"<<endl;
  25. //cout<<"Second line:"<<a2<<"x"<<"+"<<b2<<"y+"<<c2<<"=0"<<endl;
  26. //cout<<endl;
  27. if ((a1/a2)==(b1/b2)||(a1==0&&a2==0)||(b1==0&&b2==0))
  28. {
  29. if ((a1/a2)==(c1/c2)&&(b1/b2)==(c1/c2))
  30. cout<<"LINE"<<endl;//重合
  31. else if (c1==0&&c2==0)
  32. cout<<"LINE"<<endl;//重合
  33. else
  34. cout<<"NONE"<<endl;//平行
  35. }
  36. else
  37. {
  38. double x=(b2*c1-b1*c2)/(b1*a2-b2*a1);
  39. double y=(a2*c1-a1*c2)/(a1*b2-a2*b1);
  40.  
  41. printf("POINT %.2lf %.2lf\n",x,y);
  42. }
  43. //cout<<endl;
  44. }
  45. cout<<"END OF OUTPUT"<<endl;
  46. return 0;
  47. }
  48.  
Success #stdin #stdout 0s 15240KB
stdin
10 
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 
0 0 1 1 0 0 1 1 
4 0 6 0 1 2 6 9 
1 0 5 0 8 5 4 5 
1 0 5 0 5 0 1 0 
0 1 0 5 0 5 0 1
stdout
INTERSECTING LINES OUTPUT
POINT 2.00 2.00
NONE
LINE
POINT 2.00 5.00
POINT 1.07 2.20
LINE
POINT -0.43 0.00
NONE
LINE
LINE
END OF OUTPUT