fork download
  1. #include<iostream>
  2. #include<cmath>
  3. #include<algorithm>
  4. #include<cstdio>
  5. using namespace std;
  6.  
  7. const double EPS = 1E-7;
  8. int x,y,z,vx,vy,vz;
  9. double bt[100001];
  10. double et[100001];
  11. int main()
  12. {
  13. int n,r;
  14. cin>>n>>r;
  15. for (int i=0;i<n;i++)
  16. {
  17. scanf("%d%d%d",&x,&y,&z);
  18. scanf("%d%d%d",&vx,&vy,&vz);
  19. double c = 1.0*x*x+1.0*y*y+1.0*z*z-1.0*r*r;
  20. double b = 2.0*x*vx+2.0*y*vy+2.0*z*vz;
  21. double a = 1.0*vx*vx+1.0*vy*vy+1.0*vz*vz;
  22. double d = b*b - 4 * a * c;
  23. if (d>-EPS && d<0)
  24. {
  25. d = 0;
  26. }
  27. if (d<0)
  28. bt[i] = et[i] = 1E100;
  29. else
  30. {
  31. bt[i] = (-b - sqrt(d))/(2*a) - EPS;
  32. et[i] = (-b + sqrt(d))/(2*a) + EPS;
  33. }
  34. }
  35. sort(bt,bt+n);
  36. sort(et,et+n);
  37.  
  38. int m;
  39. cin>>m;
  40. int t;
  41. for (int i=0;i<m;i++)
  42. {
  43. cin>>t;
  44. int bc = lower_bound(bt,bt+n,(double)t) - bt;
  45. int ec = lower_bound(et,et+n,(double)t) - et;
  46. cout<<bc-ec<<endl;
  47. }
  48.  
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0s 4464KB
stdin
5 7
-5 2 0 -1 0 0
1 -3 2 -2 2 0
-3 -4 0 0 -2 -1
4 2 4 -1 -1 2
1 0 4 -1 1 1
6
0
1
2
3
4
5
stdout
5
5
2
1
0
0