Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Tags
more
Archives
Today
Total
관리 메뉴

코드와이

[BAEKJOON] 17143. 낚시왕 본문

acmicpc

[BAEKJOON] 17143. 낚시왕

코드와이 2021. 5. 12. 00:54

 

문제링크

www.acmicpc.net/problem/17143

 

17143번: 낚시왕

낚시왕이 상어 낚시를 하는 곳은 크기가 R×C인 격자판으로 나타낼 수 있다. 격자판의 각 칸은 (r, c)로 나타낼 수 있다. r은 행, c는 열이고, (R, C)는 아래 그림에서 가장 오른쪽 아래에 있는 칸이다.

www.acmicpc.net

 

package acmicpc.Gold2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class 낚시왕 {

	static int r, c, m, map[][], ans;
	static shark[][] arr;
	static class shark{
		int id, r, c, s, d, z;

		public shark(int id, int r, int c, int s, int d, int z) {
			super();
			this.id = id;
			this.r = r;
			this.c = c;
			this.s = s;
			this.d = d;
			this.z = z;
		}
	}
	static shark[] list;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		
		r = Integer.parseInt(st.nextToken());
		c = Integer.parseInt(st.nextToken());
		m = Integer.parseInt(st.nextToken());
		map = new int[r+1][c+1];
		list = new shark[m+1];
		for(int i = 1 ; i <= m ; i++) {
			st = new StringTokenizer(br.readLine());
			int r1 = Integer.parseInt(st.nextToken());
			int c1 = Integer.parseInt(st.nextToken());
			int s = Integer.parseInt(st.nextToken());		// 속력
			int d = Integer.parseInt(st.nextToken());		// 방향
			if(d > 2) s = s % (2*c - 2);
			else s = s % (2*r - 2);
			int z = Integer.parseInt(st.nextToken());		// 크기
			map[r1][c1] = i;
			list[i] = new shark(i,r1,c1,s,d,z);
		}
		ans = 0;
		for(int i = 1 ; i <= c ; i++) {
			go(i);
			move();
		}
		System.out.println(ans);
	}
	
	public static void go(int loc) {
		
		for(int i = 1 ; i <= r ; i++) {
			if(map[i][loc] != 0) {
				ans += list[map[i][loc]].z;
				list[map[i][loc]] = null;
				return;
			}
		}
	}
	
	static int[] dr = {0,-1,1,0,0};
	static int[] dc = {0,0,0,1,-1};
	public static void move() {
		int[][] arr = new int[r+1][c+1];
		for(shark sh : list) {
			if(sh == null) continue;
			int r1 = sh.r;
			int c1 = sh.c;
			int s = sh.s;
			int d = sh.d;
			int z = sh.z;
			
			int nr = r1;
			int nc = c1;
			for(int i = 0 ; i < s ; i++) {
				if(d <= 2 ) {
					if(nr == 1 & d == 1) d = 2;
					else if(nr == r && d == 2) d = 1;
				} else {
					if(nc == 1 & d == 4) d = 3;
					else if(nc == c && d == 3) d = 4;
				}
				nr = nr + dr[d];
				nc = nc + dc[d];
			}
			if(arr[nr][nc] == 0) {
				arr[nr][nc] = sh.id;
				list[arr[nr][nc]] = new shark(sh.id,nr,nc,s,d,z);
			}
			else {
				if(list[arr[nr][nc]].z < z) {
					list[arr[nr][nc]] = null;
					arr[nr][nc] = sh.id;
					list[sh.id] = new shark(sh.id,nr,nc,s,d,z);
				} else {
					list[sh.id] = null;
				}
			}
		}
		for(int i = 1 ; i <= r ; i++) {
			for(int j = 1 ; j <= c ; j++) {
				map[i][j] = arr[i][j];
			}
		}
	}
}

'acmicpc' 카테고리의 다른 글

[BAEKJOON] 1525. 퍼즐  (0) 2021.05.13
[BAEKJOON] 1202. 보석 도둑  (0) 2021.05.13
[BAEKJOON] 15686. 치킨 배달  (0) 2021.05.10
[BAEKJOON] 10026. 적록색약  (0) 2021.05.10
[BAEKJOON] 14500. 테트로미노  (0) 2021.05.09