Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <algorithm>
  4. #include <cstring>
  5. #define rangecheck(a,b) a<0 || a>4000 || b<0 || b>4000
  6. using namespace std;
  7. struct one {
  8. int r, c, dir, cnt, life;
  9. };
  10. void clear();
  11. bool cmp(one a, one b) {
  12. if (a.life > b.life) return true;
  13. else return false;
  14. }
  15. one oneja[1001], bag[1001];
  16. int ans=0, n, cntt=0, ttime, t_case, bag_cnt;
  17. int visited[4001][4001];
  18. int dr[] = { 1,-1,0,0 };
  19. int dc[] = { 0,0,-1,1 };
  20. bool flag = true;
  21. void print();
  22. void go() {
  23. int r, c, dir, cnt, nr, nc;
  24. int count = cntt;
  25. for (int i = 0; i < count; i++) {
  26. if (oneja[i].life < 0) continue;
  27. r = oneja[i].r;
  28. c = oneja[i].c;
  29. dir = oneja[i].dir;
  30. cnt = oneja[i].cnt;
  31. nr = r + dr[dir];
  32. nc = c + dc[dir];
  33. //printf("r = %d c = %d i =%d dir = %d cnt = %d\n", r, c, i, dir, cnt);
  34. /*if (oneja[i].life == -1) {
  35. printf("여기들어옴 비정상..\n");
  36. }*/
  37. if (rangecheck(nr, nc)) {
  38. //printf("여기들어온애는 없을텐데\n");
  39. //cntt--;
  40. oneja[i].life = -3;
  41. }
  42. else {
  43. if (visited[nr][nc] == ttime) {
  44. oneja[i].life = -1;
  45. oneja[i].r = nr;
  46. oneja[i].c = nc;
  47. }
  48. else {
  49. visited[nr][nc] = ttime;
  50. oneja[i].r = nr;
  51. oneja[i].c = nc;
  52. }
  53. }
  54. }
  55. }
  56. void bamm() {
  57. int count = cntt;
  58. bool flag2 = false;
  59. //printf("bam=========================\n");
  60. for (int i = 0; i < count; i++) {
  61. if (oneja[i].life == -1) {
  62. flag2 = true;
  63. //printf("비교 i = %d cnt = %d \n",i,oneja[i].cnt);
  64. for (int j = 0; j < count; j++) {
  65. if (oneja[i].r == oneja[j].r &&
  66. oneja[i].c == oneja[j].c && oneja[j].life!=-2) {
  67. //printf(" => r = %d c = %d j = %d cnt= %d\n",oneja[j].r,oneja[j].c, j, oneja[j].cnt);
  68. oneja[j].life = -2;
  69. ans += oneja[j].cnt;
  70. //cntt--;
  71. }
  72. }
  73. //visited[oneja[i].r][oneja[i].c] = 0;
  74. }
  75. }
  76. //if(flag2) sort(oneja, oneja + n, cmp);
  77. }
  78. int main() {
  79. int t; scanf("%d", &t);
  80. for (t_case = 1; t_case <= t; t_case++) {
  81. scanf("%d", &n);
  82. int r, c, dir, cnt;
  83. for (int i = 0; i < n; i++) {
  84. scanf("%d %d %d %d", &c, &r, &dir, &cnt);
  85. oneja[cntt].r = (r+1000)*2; oneja[cntt].c = (c+1000)*2;
  86. oneja[cntt].dir=dir; oneja[cntt].cnt = cnt;
  87. oneja[cntt++].life = 1;
  88. }
  89. for (ttime = 1; ttime <= 4010 && flag; ttime++) {
  90. //printf("ttime = %d=============================\n", ttime);
  91. go();
  92. bamm();
  93. //print();
  94. if (cntt <= 0) flag = false;
  95. }
  96.  
  97. printf("#%d %d\n", t_case, ans);
  98. clear();
  99. }
  100. return 0;
  101. }
  102. void clear() {
  103. ans = 0;
  104. flag = true;
  105. cntt = 0;
  106. memset(visited, 0, sizeof(visited));
  107. /* for (int i = 0; i < n; i++) {
  108. oneja[i].cnt = 0;
  109. oneja[i].life = 0;
  110. oneja[i].dir = -1;
  111. oneja[i].r = -1;
  112. oneja[i].c = -1;
  113. }*/
  114. }
  115. void print() {
  116. for (int i = 1980; i < 2020; i++) {
  117. for (int j = 1980; j < 2020; j++) {
  118. printf("%d", visited[i][j]);
  119. }
  120. printf("\n");
  121. }
  122. printf("\n");
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement