Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <cstring>
  4. #define rangecheck(a,b) a<0 || a>=12 || b<0 || b>=6
  5. using namespace std;
  6. struct point {
  7. int r, c;
  8. char cnt;
  9. };
  10. queue<point> q, bamm_q;
  11. char map[13][7];
  12. bool visited[13][7];
  13. bool flag;
  14. int dr[] = { -1,0,1,0 };
  15. int dc[] = { 0,1,0,-1 };
  16. int cntt = 0;
  17. int ans = 0;
  18. void bfs(int r, int c) {
  19. point tmp = { r,c,0 };
  20. q.push(tmp);
  21. visited[r][c] = true;
  22. int nr, nc;
  23. while (!q.empty()) {
  24. r = q.front().r;
  25. c = q.front().c;
  26. bamm_q.push(q.front());
  27. q.pop();
  28. cntt++;
  29. //printf("%d %d %d %c\n", r, c, cntt, map[r][c]);
  30. for (int i = 0; i < 4; i++) {
  31. nr = r + dr[i];
  32. nc = c + dc[i];
  33. if (rangecheck(nr, nc)) continue;
  34. if (map[nr][nc] == map[r][c] && !visited[nr][nc]) {
  35. visited[nr][nc] = true;
  36. q.push({ nr,nc,0 });
  37. }
  38. }
  39. }
  40. //printf("\n");
  41. }
  42. void print() {
  43. for (int i = 0; i < 12; i++) {
  44. for (int j = 0; j < 6; j++) {
  45. printf("%c", map[i][j]);
  46. }
  47. printf("\n");
  48. }
  49. printf("\n");
  50. }
  51. void bamm() {
  52. for (int i = 0; i < 12; i++) {
  53. for (int j = 0; j < 6; j++) {
  54. if (map[i][j] != '.') {
  55. cntt = 0;
  56. bfs(i, j);
  57. if (cntt >= 4) {
  58. flag = true;
  59. while (!bamm_q.empty()) {
  60. map[bamm_q.front().r][bamm_q.front().c] = '.';
  61. bamm_q.pop();
  62. }
  63. }
  64. else {
  65. while (!bamm_q.empty()) {
  66. bamm_q.pop();
  67. }
  68. }
  69. }
  70. }
  71. }
  72. }
  73. void down() {
  74. for (int j = 0; j < 6; j++) {
  75. for (int i = 11; i >= 0; i--) {
  76. if (map[i][j] != '.') {
  77. q.push({ i,j,map[i][j] });
  78. map[i][j] = '.';
  79. }
  80. }
  81. int ii = 11;
  82. while (!q.empty()) {
  83. map[ii--][j] = q.front().cnt;
  84. q.pop();
  85. }
  86. }
  87. }
  88. void go() {
  89. flag = true;
  90. while (flag) {
  91. flag = false;
  92. bamm();
  93. down();
  94. memset(visited, false, sizeof(visited));
  95. //print();
  96. if (flag) ans++;
  97. }
  98. }
  99. int main() {
  100. for (int i = 0; i < 12; i++) {
  101. for (int j = 0; j < 6; j++) {
  102. scanf(" %1c", &map[i][j]);
  103. }
  104. }
  105. go();
  106. printf("%d\n", ans);
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement