백준 olympiad 2669

이동천·2021년 11월 24일
0

올림피아드 백준

목록 보기
3/4

https://www.acmicpc.net/problem/2669

  1. 문제 해결방법은 여타의 dfs와 비슷하다 주어진 수에따라 사각형 넓이를 탐색하고 이를 방문체크하여 중복을 없애주면 된다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class baekjoon_2669 {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		boolean check[][] = new boolean[101][101];
		int answer =0;
		for(int i =0; i<4 ; ++i) {
			st = new StringTokenizer(br.readLine());
			int sx =Integer.parseInt(st.nextToken());
			int sy = Integer.parseInt(st.nextToken());
			int ex = Integer.parseInt(st.nextToken());
			int ey = Integer.parseInt(st.nextToken());
			//넓이만큼 탐색후 중복방지 
			for(int y= sy; y<ey; ++y) {
				for(int x=sx; x<ex; ++x) {
					if(!check[y][x]) {
						check[y][x] = true;
						answer++;
					}
				}
			}
		}
		System.out.println(answer);

	}

}

메모리14040 속도124

profile
안드개발자

0개의 댓글

Powered by GraphCDN, the GraphQL CDN