Advertisement
Maruf_Hasan

378 uva

May 10th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. double triangle(double x1,double y1,double x2,double y2,double x3,double y3)
  5. {
  6. double ans1=(x1*y2)+(x2*y3)+(x3*y1);
  7. double ans2=(y1*x2)+(y2*x3)+(y3*x1);
  8. return ans1-ans2;
  9. }
  10. void myfunc(double a1,double b1,double c1,double a2,double b2,double c2)
  11. {
  12. double x=(b1*c2-b2*c1)/(double)(a1*b2-a2*b1);
  13. double y=(c1*a2-c2*a1)/(double)(a1*b2-a2*b1);
  14. //cout<<fixed<<setprecision(2);
  15. printf("POINT %.02lf %.02lf\n",x,y);
  16. }
  17. int main()
  18. {
  19. //freopen("378.txt","r",stdin);
  20. //freopen("378out.txt","w",stdout);
  21. int t,flag=0;
  22. cin>>t;
  23. while(t--)
  24. {
  25. double x1,y1,x2,y2,x3,y3,x4,y4;
  26. cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
  27. if(!flag){
  28. cout<<"INTERSECTING LINES OUTPUT"<<endl;
  29. flag=1;
  30. }
  31. if(x1!=x2)
  32. {
  33.  
  34. double slope1=(y1-y2)/(x1-x2);
  35. double slope2=(y3-y4)/(x3-x4);
  36. // cout<<slope1<<" "<<slope2<<endl;
  37. if(slope1==slope2)
  38. {
  39. double area=triangle(x1,y1,x2,y2,x3,y3);
  40. if(area==0.0)
  41. {
  42. cout<<"LINE"<<endl;
  43. }
  44. else
  45. {
  46. cout<<"NONE"<<endl;
  47. }
  48. }
  49. else
  50. {
  51. double a1,b1,c1,a2,b2,c2;
  52. a1=y2-y1;
  53. b1=x1-x2;
  54. c1=(y1*x2)-(x1*y2);
  55. a2=y4-y3;
  56. b2=x3-x4;
  57. c2=(y3*x4)-(x3*y4);
  58. myfunc(a1,b1,c1,a2,b2,c2);
  59. }
  60. }
  61. else
  62. {
  63. /*cout<<x1<<" "<<y1<<endl;
  64. cout<<x2<<" "<<y2<<endl;
  65. cout<<x3<<" "<<y3<<endl;
  66. cout<<x4<<" "<<y4<<endl;*/
  67. double area1=triangle(x1,y1,x2,y2,x3,y3);
  68. double area2=triangle(x1,y1,x2,y2,x4,y4);
  69. if(area1==0.0 && area2==0.0)
  70. {
  71. cout<<"LINE"<<endl;
  72. continue;
  73. }
  74. double a1,b1,c1,a2,b2,c2;
  75. a1=y2-y1;
  76. b1=x1-x2;
  77. c1=(y1*x2)-(x1*y2);
  78. a2=y4-y3;
  79. b2=x3-x4;
  80. c2=(y3*x4)-(x3*y4);
  81. myfunc(a1,b1,c1,a2,b2,c2);
  82. }
  83.  
  84. }
  85. cout<<"END OF OUTPUT"<<endl;
  86. return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement