Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4. #include <string>
  5. #include <cmath>
  6. #include <queue>
  7. #include <algorithm>
  8. #include <random>
  9.  
  10. using namespace std;
  11.  
  12. int mas[12][12];
  13. int k;
  14.  
  15. struct Point {
  16. int x, y;
  17. };
  18.  
  19. vector<Point> fir, sec;
  20. vector<pair<int, int> > go_to = {{1, 1}, {1, 0}, {1, -1}, {0, 1}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}};
  21. Point best_start, best_go, best_shot;
  22. int prior = -1;
  23.  
  24. bool can_go(Point p) {
  25. int x = p.x, y = p.y;
  26. if (!mas[x - 1][y - 1] || !mas[x - 1][y] || !mas[x - 1][y + 1]
  27. || !mas[x][y + 1] || !mas[x][y - 1]
  28. || !mas[x + 1][y - 1] || !mas[x + 1][y] || !mas[x + 1][y + 1])
  29. return true;
  30. return false;
  31. }
  32.  
  33. void try_shot(Point p, int xx, int yy) {
  34. int pri = 0;
  35. for (int i = 0; i < 8; ++i)
  36. if (mas[p.x + go_to[i].first][p.y + go_to[i].second] == -1)
  37. pri++;
  38. for (int i = 0; i < 8; ++i) {
  39. int addx = go_to[i].first, addy = go_to[i].second, pr = pri;
  40. int x = xx + addx, y = yy + addy;
  41. while (!mas[x][y]) {
  42. for (int j = 0; j < 8; ++j) {
  43. if (mas[x + go_to[j].first][y + go_to[j].second] == 1)
  44. pr--;
  45. if (mas[x + go_to[j].first][y + go_to[j].second] == 2) {
  46. pr++;
  47. int temp = 0;
  48. for (int k = 0; k < 8; ++k) {
  49. if (mas[x + go_to[j].first + go_to[k].first][y + go_to[j].second + go_to[k].second]) {
  50. pr++;
  51. temp++;
  52. }
  53. }
  54. if (temp == 7)
  55. pr += 100000;
  56. }
  57. }
  58. if (pr > prior) {
  59. best_start.x = p.x - 1;
  60. best_start.y = p.y - 1;
  61. best_go.x = xx - 1;
  62. best_go.y = yy - 1;
  63. best_shot.x = x - 1;
  64. best_shot.y = y - 1;
  65. prior = pr;
  66. }
  67. x += addx;
  68. y += addy;
  69. }
  70. }
  71. }
  72.  
  73. void try_go(Point p) {
  74. mas[p.x][p.y] = 0;
  75. for (int i = 0; i < 8; ++i) {
  76. int addx = go_to[i].first, addy = go_to[i].second;
  77. int x = p.x + addx, y = p.y + addy;
  78. while (!mas[x][y]) {
  79. mas[x][y] = 1;
  80. try_shot(p, x, y);
  81. mas[x][y] = 0;
  82. x += addx;
  83. y += addy;
  84. }
  85. }
  86. mas[p.x][p.y] = 1;
  87. }
  88.  
  89. int main() {
  90. for (int i = 0; i < 12; ++i)
  91. for (int j = 0; j < 12; ++j)
  92. mas[i][j] = -1;
  93. for (int i = 1; i <= 10; ++i)
  94. for (int j = 1; j <= 10; ++j)
  95. cin >> mas[i][j];
  96. cin >> k;
  97. if (k == 2) {
  98. for (int i = 1; i <= 10; ++i) {
  99. for (int j = 1; j <= 10; ++j) {
  100. if (mas[i][j] == 1)
  101. mas[i][j] = 2;
  102. if (mas[i][j] == 2)
  103. mas[i][j] = 1;
  104. }
  105. }
  106. }
  107. for (int i = 1; i <= 10; ++i) {
  108. for (int j = 1; j <= 10; ++j) {
  109. if (mas[i][j] == 1) {
  110. Point temp;
  111. temp.x = i;
  112. temp.y = j;
  113. fir.push_back(temp);
  114. }
  115. if (mas[i][j] == 2) {
  116. Point temp;
  117. temp.x = i;
  118. temp.y = j;
  119. sec.push_back(temp);
  120. }
  121. }
  122. }
  123. for (int i = 0; i < 4; ++i) {
  124. if (can_go(fir[i]))
  125. try_go(fir[i]);
  126. }
  127. cout << best_start.x << " " << best_start.y << "\n";
  128. cout << best_go.x << " " << best_go.y << "\n";
  129. cout << best_shot.x << " " << best_shot.y << "\n";
  130. return 0;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement