fork download
  1. #include <iostream>
  2. #include <math.h>
  3. #include <iomanip>
  4. using namespace std;
  5. int main() {
  6. long long n, z, dir;
  7. long long x = 0, y = 0, ne = 0, se = 0;
  8. double dx, dy;
  9.  
  10. cin >> n;
  11. while(n--) {
  12. cin >> dir >> z;
  13. switch (dir) {
  14. case 1: y+=z; break;
  15. case 5: y-=z; break;
  16. case 3: x+=z; break;
  17. case 7: x-=z; break;
  18.  
  19. case 2: ne+=z; break;
  20. case 6: ne-=z; break;
  21. case 4: se+=z; break;
  22. case 8: se-=z; break;
  23.  
  24. }
  25. }
  26. dx = x + (ne + se)*M_SQRT1_2;
  27. dy = y + (ne - se)*M_SQRT1_2;
  28. cout << fixed << setprecision(3) << dx << " " << dy;
  29. return 0;
  30. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
0.000 0.000