Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. long long k, d, t, m, c, sol;
  7.  
  8. cin >> k >> d >> t;
  9.  
  10. long long nr = k / d;
  11. if(nr * d < k)
  12. m = (nr + 1) * d;
  13. else
  14. m = nr * d;
  15.  
  16. c = (2LL * t) / (m + k);
  17. sol = c * m;
  18.  
  19. t -= c * ((m + k) / 2);
  20.  
  21. bool r = false;
  22. if((m + k) % 2 == 1) {
  23. t -= c / 2;
  24. if(c % 2 == 1) {
  25. t -= 1;
  26. r = true;
  27. }
  28. }
  29.  
  30. if(t < k) {
  31. sol += t;
  32. cout << sol;
  33. if(r)
  34. cout << ".5";
  35. }
  36. else if(t == k) {
  37. sol += t;
  38. if(r)
  39. sol += 1;
  40. cout << sol << ".0";
  41. }
  42. else {
  43. sol += k;
  44. t -= k;
  45. sol += 2 * t;
  46. if(r)
  47. sol += 1;
  48. cout << sol << ".0";
  49. }
  50.  
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement