fork(1) download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main() {
  6. const float e=10e-8;
  7. int x1,y1,x2,y2;
  8. cin>>x1>>y1>>x2>>y2;
  9. double d,a,b;
  10. d = abs((y2 * x1 - x2 * y1) / sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
  11. a = sqrt(x1 * x1 + y1 * y1);
  12. b = sqrt(x2 * x2 + y2 * y2);
  13. int count=0;
  14. if ((2 * x1 * x1 - 2 * x1 * x2 + 2 * y1 * y1 - 2 * y1 * y2 < 0) or (2 * x2 * x2 - 2 * x1 * x2 + 2 * y2 * y2 - 2 * y1 * y2 < 0))
  15. count =(int)(max(a,b)+e) - (int)(min(a,b)-e);
  16. else {
  17. count = (int)(a+e)-(int)(d-e);
  18. count = count + (int)(b+e) - (int)(d-e);
  19. if ((abs(round(d) - d) < e) and (abs(d) > e)){
  20. count--;
  21. }
  22. }
  23. cout<<count;
  24. return 0;
  25. }
Success #stdin #stdout 0s 4388KB
stdin
-2 2 2 4
stdout
2