Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <algorithm>
- #include <cstring>
- #define rangecheck(a,b) a<0 || a>4000 || b<0 || b>4000
- using namespace std;
- struct one {
- int r, c, dir, cnt, life;
- };
- void clear();
- bool cmp(one a, one b) {
- if (a.life > b.life) return true;
- else return false;
- }
- one oneja[1001], bag[1001];
- int ans=0, n, cntt=0, ttime, t_case, bag_cnt;
- int visited[4001][4001];
- int dr[] = { 1,-1,0,0 };
- int dc[] = { 0,0,-1,1 };
- bool flag = true;
- void print();
- void go() {
- int r, c, dir, cnt, nr, nc;
- int count = cntt;
- for (int i = 0; i < count; i++) {
- if (oneja[i].life < 0) continue;
- r = oneja[i].r;
- c = oneja[i].c;
- dir = oneja[i].dir;
- cnt = oneja[i].cnt;
- nr = r + dr[dir];
- nc = c + dc[dir];
- //printf("r = %d c = %d i =%d dir = %d cnt = %d\n", r, c, i, dir, cnt);
- /*if (oneja[i].life == -1) {
- printf("여기들어옴 비정상..\n");
- }*/
- if (rangecheck(nr, nc)) {
- //printf("여기들어온애는 없을텐데\n");
- //cntt--;
- oneja[i].life = -3;
- }
- else {
- if (visited[nr][nc] == ttime) {
- oneja[i].life = -1;
- oneja[i].r = nr;
- oneja[i].c = nc;
- }
- else {
- visited[nr][nc] = ttime;
- oneja[i].r = nr;
- oneja[i].c = nc;
- }
- }
- }
- }
- void bamm() {
- int count = cntt;
- bool flag2 = false;
- //printf("bam=========================\n");
- for (int i = 0; i < count; i++) {
- if (oneja[i].life == -1) {
- flag2 = true;
- //printf("비교 i = %d cnt = %d \n",i,oneja[i].cnt);
- for (int j = 0; j < count; j++) {
- if (oneja[i].r == oneja[j].r &&
- oneja[i].c == oneja[j].c && oneja[j].life!=-2) {
- //printf(" => r = %d c = %d j = %d cnt= %d\n",oneja[j].r,oneja[j].c, j, oneja[j].cnt);
- oneja[j].life = -2;
- ans += oneja[j].cnt;
- //cntt--;
- }
- }
- //visited[oneja[i].r][oneja[i].c] = 0;
- }
- }
- //if(flag2) sort(oneja, oneja + n, cmp);
- }
- int main() {
- int t; scanf("%d", &t);
- for (t_case = 1; t_case <= t; t_case++) {
- scanf("%d", &n);
- int r, c, dir, cnt;
- for (int i = 0; i < n; i++) {
- scanf("%d %d %d %d", &c, &r, &dir, &cnt);
- oneja[cntt].r = (r+1000)*2; oneja[cntt].c = (c+1000)*2;
- oneja[cntt].dir=dir; oneja[cntt].cnt = cnt;
- oneja[cntt++].life = 1;
- }
- for (ttime = 1; ttime <= 4010 && flag; ttime++) {
- //printf("ttime = %d=============================\n", ttime);
- go();
- bamm();
- //print();
- if (cntt <= 0) flag = false;
- }
- printf("#%d %d\n", t_case, ans);
- clear();
- }
- return 0;
- }
- void clear() {
- ans = 0;
- flag = true;
- cntt = 0;
- memset(visited, 0, sizeof(visited));
- /* for (int i = 0; i < n; i++) {
- oneja[i].cnt = 0;
- oneja[i].life = 0;
- oneja[i].dir = -1;
- oneja[i].r = -1;
- oneja[i].c = -1;
- }*/
- }
- void print() {
- for (int i = 1980; i < 2020; i++) {
- for (int j = 1980; j < 2020; j++) {
- printf("%d", visited[i][j]);
- }
- printf("\n");
- }
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement