Source code for submission s693

main.cpp

  1. #define PROJECT 4
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <queue>
  6. #include <limits>
  7.  
  8. typedef unsigned long long ull;
  9.  
  10. using namespace std;
  11.  
  12. #if PROJECT == 1
  13.  
  14.  
  15. int main() {
  16. int l, a;
  17.  
  18. while (cin >> l >> a) {
  19. int pos;
  20. char dir;
  21. cin >> pos >> dir;
  22.  
  23. }
  24. }
  25.  
  26. #elif PROJECT == 2
  27. #elif PROJECT == 3
  28. #elif PROJECT == 4
  29.  
  30. struct task {
  31. int x, y;
  32. task(int _x, int _y) : x(_x), y(_y) {}
  33. };
  34.  
  35. int grid[100][100];
  36.  
  37. int main() {
  38. int r, c, gr, gc, lr, lc;
  39. while (cin >> r >> c >> gr >> gc >> lr >> lc) {
  40. for (int i = 0; i < r; i++ ) {
  41. for (int j = 0; j < c; j++) {
  42. grid[i][j] = numeric_limits<int>::max();
  43. }
  44. }
  45. gr--, gc--, lr--, lc--;
  46. grid[gr][gc] = 0;
  47. queue<task> todo;
  48. todo.push(task(gr, gc));
  49.  
  50. while (!todo.empty()) {
  51. task next = todo.front(); todo.pop();
  52.  
  53. for (int i = -2; i <= 2; i++) {
  54. if (i == 0 || next.x + i < 0 || next.x + i > c - 1) continue;
  55.  
  56. if (abs(i) == 1) {
  57. for (int j = -2; j <= 2; j += 4) {
  58. if (next.y + j < 0 || next.y + j > r - 1) continue;
  59.  
  60. int tx = next.x + i;
  61. int ty = next.y + j;
  62. if (grid[ty][tx] > grid[next.y][next.x] + 1) {
  63. grid[ty][tx] = grid[next.y][next.x] + 1;
  64. todo.push(task(tx, ty));
  65. }
  66. }
  67. } else if (abs(i) == 2) {
  68.  
  69. for (int j = -1; j <= 1; j += 2) {
  70. if (next.y + j < 0 || next.y + j > r - 1) continue;
  71.  
  72. int tx = next.x + i;
  73. int ty = next.y + j;
  74. if (grid[ty][tx] > grid[next.y][next.x] + 1) {
  75. grid[ty][tx] = grid[next.y][next.x] + 1;
  76.  
  77. todo.push(task(tx, ty));
  78. }
  79. }
  80. }else {
  81. cerr << "dafuq?" << endl;
  82. }
  83. }
  84.  
  85.  
  86. }
  87.  
  88. if (grid[lr][lc] == numeric_limits<int>::max()) {
  89. cout << "impossible" << endl;
  90.  
  91. } else {
  92. cout << grid[lr][lc] << endl;
  93. }
  94.  
  95. }
  96.  
  97. return 0;
  98. }
  99.  
  100. #elif PROJECT == 5
  101.  
  102. #elif PROJECT == 6
  103.  
  104. int main() {
  105.  
  106. unsigned long long m, p, l, e ,r, s, n;
  107.  
  108. while (cin >> m >> p >> l >> e >> r >> s >> n) {
  109. for (ull i = 0; i < n; i++) {
  110. ull m1, p1, l1;
  111. m1 = p / s;
  112. p1 = l / r;
  113. l1 = m * e;
  114.  
  115. m = m1; p = p1; l = l1;
  116. }
  117. cout << m << endl;
  118. }
  119.  
  120. return 0;
  121. }
  122.  
  123. #endif
  124.