fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. double x1,x2,y2,y_1,dist;
  8.  
  9. bool lies_in_range(double x,double y)
  10. {
  11. double dist1= sqrt((y-y_1)*(y-y_1)+(x-x1)*(x-x1));
  12. double dist2=sqrt((y-y2)*(y-y2)+(x-x2)*(x-x2));
  13. //cout<<"hello world\n";
  14. //cout<<dist<<" "<<dist1+dist2<<endl;
  15. if((dist1+dist2)==dist){
  16. cout<<"y no cor\n";
  17. return true;
  18. }
  19. else{
  20. cout<<"not equal\n";
  21. return false;
  22. }
  23. }
  24.  
  25.  
  26. int main()
  27. {
  28.  
  29. double a1,b1,c1,pt_x,pt_y;
  30. double a2,b2,c2;
  31.  
  32. int n,cnt=0;
  33. cin>>x1>>y_1;
  34. cin>>x2>>y2;
  35. double det;
  36. a2=-(y2-y_1);b2=x2-x1;c2=y_1*(x2-x1)-x1*(y2-y_1);
  37. dist=sqrt((y2-y_1)*(y2-y_1)+(x2-x1)*(x2-x1));
  38. cin>>n;
  39. for(int i=0;i<n;i++){
  40. cin>>a1>>b1>>c1;
  41. det = a1*b2 - a2*b1;
  42. if(det == 0){
  43. continue;
  44. }else{
  45. pt_x = (b2*c1 - b1*c2)/det;
  46. pt_y = (a1*c2 - a2*c1)/det;
  47. // cout<<pt_x<<" "<<pt_y<<endl;
  48. if(lies_in_range(pt_x,pt_y)){
  49. cnt++;
  50. }
  51. }
  52. }
  53. cout<<cnt<<"\n";
  54. return 0;
  55. }
  56.  
Success #stdin #stdout 0s 3476KB
stdin
1 1
-1 -1
2
0 1 0
1 0 0
stdout
hello world
y no cor
hello world
y no cor
2