Advertisement
Guest User

Untitled

a guest
Aug 16th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. //#pragma GCC optimize("unroll-loops")
  4. //#pragma GCC optimize("Ofast")
  5. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
  6. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  7.  
  8. #define F first
  9. #define S second
  10. #define pb push_back
  11. #define ll long long
  12. #define ld long double
  13. #define endl '\n'
  14. #define pii pair <int, int>
  15. #define pll pair <ll, ll>
  16. #define pld pair <ld, ld>
  17.  
  18. using namespace std;
  19.  
  20. const int N = 1e3 + 5;
  21.  
  22. int main() {
  23. ios_base::sync_with_stdio(0);
  24. cin.tie(0);
  25. cout.tie(0);
  26. #ifdef LOCAL
  27. freopen("input.txt", "r", stdin);
  28. freopen("output.txt", "w", stdout);
  29. #else
  30. freopen("garden.in", "r", stdin);
  31. freopen("garden.out", "w", stdout);
  32. #endif
  33. int x, y;
  34. cin >> x >> y;
  35. x = abs(x);
  36. y = abs(y);
  37. if (!((x % 2 && y % 2) || (x % 4 == 0 && y % 4 == 0))) {
  38. cout << -1;
  39. return 0;
  40. }
  41. int k1 = x / 4;
  42. int k2 = y / 4;
  43. ld ans = 0;
  44. ans += (2 * sqrt(2) + 4) * min(k1, k2);
  45. x -= min(k1, k2) * 4;
  46. y -= min(k1, k2) * 4;
  47. if (x < y) {
  48. swap(x, y);
  49. }
  50. if (y == 3) ans += 2;
  51. ans += (x / 4) * (2 + 2 * sqrt(2));
  52. x %= 4;
  53. if (x == 1) ans += sqrt(2);
  54. if (x == 3) ans += sqrt(2) + 2;
  55. cout << fixed << setprecision(10) << ans;
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement