Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. typedef struct __shark {
  8. int dir, vc, size;
  9. __shark() : dir(0), vc(0), size(0) {}
  10. __shark(int dir, int vc, int size) :
  11. dir(dir), vc(vc), size(size) {}
  12. } SHARK;
  13.  
  14. typedef struct __sharkinfo {
  15. int x, y, dir, vc, size;
  16. __sharkinfo() : x(0), y(0), dir(0), vc(0), size(0) {}
  17. __sharkinfo(int x, int y, int dir, int vc, int size) :
  18. x(x), y(y), dir(dir), vc(vc), size(size) {}
  19. } SHARKINFO;
  20.  
  21. bool cmp(const SHARK &u, const SHARK &v) {
  22. return u.size > v.size;
  23. }
  24.  
  25. int dx[5] = { 0, -1, 1, 0, 0 };
  26. int dy[5] = { 0, 0, 0, 1, -1 };
  27. bool check[100][100];
  28.  
  29. int main(void) {
  30. ios_base::sync_with_stdio(false);
  31. cin.tie(nullptr);
  32.  
  33. int n, m, k;
  34. cin >> n >> m >> k;
  35. vector<vector<vector<SHARK>>> mat(n, vector<vector<SHARK>>(m, vector<SHARK>()));
  36. vector<SHARKINFO> sharkinfo;
  37. for (int i = 0; i < k; i++) {
  38. int x, y, s, d, z;
  39. cin >> x >> y >> s >> d >> z;
  40. x -= 1, y -= 1;
  41. mat[x][y].push_back(SHARK(d, s, z));
  42. sharkinfo.push_back(SHARKINFO(x, y, d, s, z));
  43. }
  44.  
  45. int ans = 0;
  46. for (int col = 0; col < m; col++) {
  47. int cx = -1, cy = -1;
  48. for (int i = 0; i < n; i++) {
  49. if (mat[i][col].size() > 0) {
  50. cx = i, cy = col;
  51. ans += mat[i][col][0].size;
  52. mat[i][col].erase(mat[i][col].begin(), mat[i][col].end());
  53. break;
  54. }
  55. }
  56.  
  57. vector<vector<vector<SHARK>>> tmpmat(n, vector<vector<SHARK>>(m, vector<SHARK>()));
  58. vector<SHARKINFO> tmp_sharkinfo;
  59. for (int i = 0; i < sharkinfo.size(); i++) {
  60. int x, y, s, d, z;
  61. x = sharkinfo[i].x;
  62. y = sharkinfo[i].y;
  63. s = sharkinfo[i].vc;
  64. d = sharkinfo[i].dir;
  65. z = sharkinfo[i].size;
  66.  
  67. if (x == cx && y == cy) continue;
  68.  
  69. int tx = x, ty = y;
  70. for (int j = 0; j < s; j++) {
  71. tx += dx[d];
  72. ty += dy[d];
  73. if (tx < 0 || ty < 0 || tx > n - 1 || ty > m - 1) {
  74. if (d == 1) d = 2;
  75. else if (d == 2) d = 1;
  76. else if (d == 3) d = 4;
  77. else if (d == 4) d = 3;
  78. j -= 1;
  79. tx += dx[d];
  80. ty += dy[d];
  81. continue;
  82. }
  83. }
  84. tmp_sharkinfo.push_back(SHARKINFO(tx, ty, d, s, z));
  85. tmpmat[tx][ty].push_back(SHARK(d, s, z));
  86. }
  87.  
  88. memset(check, 0, sizeof(check));
  89. sharkinfo = vector<SHARKINFO>();
  90. for (int i = 0; i < tmp_sharkinfo.size(); i++) {
  91. int x, y;
  92. x = tmp_sharkinfo[i].x;
  93. y = tmp_sharkinfo[i].y;
  94.  
  95. sort(tmpmat[x][y].begin(), tmpmat[x][y].end(), cmp);
  96. if (tmpmat[x][y].size() > 1) {
  97. tmpmat[x][y].erase(tmpmat[x][y].begin() + 1, tmpmat[x][y].end());
  98. }
  99. if (!check[x][y]) {
  100. check[x][y] = true;
  101. sharkinfo.push_back(SHARKINFO(x, y, tmpmat[x][y].begin()->dir, tmpmat[x][y].begin()->vc, tmpmat[x][y].begin()->size));
  102. }
  103. }
  104.  
  105. mat = tmpmat;
  106. }
  107.  
  108. cout << ans << '\n';
  109. return 0;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement