1 minute read

๐Ÿ“Œ ๋‚œ์ด๋„

๐Ÿฅˆ Silver 5


๐Ÿ“Œ ๋ฌธ์ œ

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


image


๐Ÿ“Œ ํ’€์ด

๋ฌธ์ œ๋ฅผ ์ฒ˜์Œ ๋”ฑ ๋ณด์ž๋งˆ์ž ๋ฐ”๋กœ ๋“  ์ƒ๊ฐ์ด ํ•˜๋‚˜ ์žˆ์—ˆ๋‹ค.
๋Œ€์ฒด ์ด๊ฒƒ์„ ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์•ผ์ง€ ์ด์ „์— ์ฑ„์› ๋˜ ๊ณต๊ฐ„์„ ์ œ์™ธํ•˜๊ณ  ์ถ”๊ฐ€์ ์œผ๋กœ ๊ณต๊ฐ„์˜ ๋„“์ด๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์„๊นŒ์˜€๋‹ค.
๊ณ ๋ฏผ์„ ํ•˜๋‹ค๊ฐ€ ์ด๊ฑฐ๋Š” ์ง„์งœ๋กœ ๊ณต๊ฐ„์„ ๋งŒ๋“ค์–ด์•ผ๊ฒ ๋ผ๋Š” ๊ฒฐ๋ก ์ด ๋‚ฌ๋‹ค.

๋ฐ”๋กœ ๋ฐฐ์—ด๋กœ 100x100์˜ ๊ณต๊ฐ„์„ ๋งŒ๋“ค์–ด์„œ ์ƒ‰์ข…์ด๋ฅผ ๋ถ™์ผ๋•Œ๋งˆ๋‹ค ๊ทธ ๊ณต๊ฐ„์„ true๋กœ ๋ฐ”๊พผํ›„ ๋‚˜์ค‘์— ํ•œ๋ฒˆ์— true์ธ ๋ฐฐ์—ด์˜ ๊ฐœ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ˜•์‹์œผ๋กœ ๊ตฌํ˜„์„ ํ•˜์˜€๋‹ค.
์ดํ›„ ์™„์„ฑ๋œ ์ฝ”๋“œ์ด๋‹ค.


๐Ÿ“Œ Code

package Math;
import java.io.*;
import java.util.StringTokenizer;

public class N2563 {
    public static boolean[][] paper = new boolean[100][100];
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int flag = Integer.parseInt(st.nextToken());

        for (int i = 0; i < 100; i++) {
            for (int j = 0; j < 100; j++) {
                paper[i][j] = false;
            }
        }
        String[] str;
        for (int i = 0; i < flag; i++) {
            st = new StringTokenizer(br.readLine());
            Confetti(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));
        }

        int count = 0;
        for (int i = 0; i < 100; i++) {
            for (int j = 0; j < 100; j++) {
                if(paper[i][j]){
                    count++;
                }
            }
        }
        System.out.println(count);
    }

    public static void Confetti(int x, int y){
        for (int i = x; i < x+10; i++) {
            for (int j = y; j < y+10; j++) {
                paper[i][j] = true;
            }
        }
    }
}

package (์ด๋ฆ„); ๋ฅผ ๋•Œ๊ณ , class ์ด๋ฆ„์„ Main์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋ฉด ๋œ๋‹ค.



๊ฐœ์ธ ๊ณต๋ถ€ ๊ธฐ๋ก์šฉ ๋ธ”๋กœ๊ทธ์ž…๋‹ˆ๋‹ค.
ํ‹€๋ฆฌ๊ฑฐ๋‚˜ ์˜ค๋ฅ˜๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ ์ œ๋ณดํ•ด์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.๐Ÿ˜