알고리즘/백준 BOJ
[JAVA] 백준 2567 색종이-2
goodorbad
2021. 8. 30. 02:18
728x90
https://www.acmicpc.net/problem/2567
2567번: 색종이 - 2
가로, 세로의 크기가 각각 100인 정사각형 모양의 흰색 도화지가 있다. 이 도화지 위에 가로, 세로의 크기가 각각 10인 정사각형 모양의 검은색 색종이를 색종이의 변과 도화지의 변이 평행하도록
www.acmicpc.net
풀이 과정
수정중..
주의할 점
배열 범위 주의
JAVA 코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BOJ_2567_색종이2 {
static StringTokenizer st;
static int t=100;
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
int N=Integer.parseInt(br.readLine());
int[][] map=new int[t+1][t+1];
int result=0;
for (int i = 0; i < N; i++) {
st=new StringTokenizer(br.readLine());
int C=Integer.parseInt(st.nextToken());
int R=Integer.parseInt(st.nextToken());
for (int r= R; r < R+10; r++) {
for (int c = C; c < C+10; c++) {
map[r][c]=1;
}
}
}
int before=0;
for (int r= 1; r < t+1; r++) {
for (int c = 1; c < t+1; c++) {
if(map[r][c]!=before) result++;
before=map[r][c];
}
}
before=0;
for (int c= 1; c < t+1; c++) {
for (int r = 1; r < t+1; r++) {
if(map[r][c]!=before) result++;
before=map[r][c];
}
}
System.out.println(result);
}
}
728x90