๊ธฐ๋ก๋ฐฉ

BOJ_2563 : ์ƒ‰์ข…์ด ๋ณธ๋ฌธ

CodingTest/Java

BOJ_2563 : ์ƒ‰์ข…์ด

Soom_1n 2023. 1. 13. 09:29

๐Ÿ‘‰ ๋ฌธ์ œ๋งํฌ

 

2563๋ฒˆ: ์ƒ‰์ข…์ด

์ฒซ์งธ ์ค„์— ์ƒ‰์ข…์ด์˜ ์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ด์–ด ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ƒ‰์ข…์ด๋ฅผ ๋ถ™์ธ ์œ„์น˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ƒ‰์ข…์ด๋ฅผ ๋ถ™์ธ ์œ„์น˜๋Š” ๋‘ ๊ฐœ์˜ ์ž์—ฐ์ˆ˜๋กœ ์ฃผ์–ด์ง€๋Š”๋ฐ ์ฒซ ๋ฒˆ์งธ ์ž์—ฐ์ˆ˜๋Š” ์ƒ‰์ข…์ด์˜ ์™ผ์ชฝ ๋ณ€

www.acmicpc.net



๐Ÿ”ธ ๋ฌธ์ œ ๋ถ„์„ ๐Ÿ”ธ

  • 100x100 ํฐ ์ข…์ด์— 10x10 ์ƒ‰์ข…์ด๋“ค์„ ๋†“์•˜์„๋•Œ ์ƒ‰์ข…์ด๊ฐ€ ๋ถ™์€ ์นธ์˜ ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

๐Ÿ”ธ ์ฝ”๋“œ ๐Ÿ”ธ

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean[][] arr = new boolean[100][100];
		for (int i = 0; i < 100; i++) {
			for (int j = 0; j < 100; j++) {
				arr[i][j] = false;
			}
		}
		
		for (int i = 0; i < n; i++) {
			int left = sc.nextInt();
			int bottom = sc.nextInt();
			for (int j = 100-bottom-10; j < 100-bottom; j++) {
				for (int k = left; k < left+10; k++) {
					arr[j][k] = true;
				}
			}
		}
		
		int answer = 0;
		for (int i = 0; i < 100; i++) {
			for (int j = 0; j < 100; j++) {
				if (arr[i][j])
					answer++;
			}
		}
		System.out.println(answer);
	}
}

๐Ÿ”ธ ์ฝ”๋“œ ํ•ด์„ ๐Ÿ”ธ

  • ์ƒ‰์ข…์ด๋“ค์˜ ์ •๋ณด๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค.
  • ์ •๋ณด๋ฅผ ํ† ๋Œ€๋กœ 100x100 ํฐ ์ข…์ด์— ์ƒ‰์ข…์ด ์˜์—ญ๋งŒํผ true๋กœ ์ฑ„์šด๋‹ค
    • ์ƒ‰์ข…์ด์˜ ์ •๋ณด๋Š” ์ขŒํ•˜๋‹จ ์ •๋ณด์ด๋ฏ€๋กœ ์ธ๋ฑ์Šค๋ฅผ 10์›€์ง์—ฌ์„œ ๋ฐ˜๋ณตํ•œ๋‹ค.
  • ํฐ ์ข…์ด๋ฅผ ์ˆœํšŒํ•˜๋ฉฐ true์˜ ๊ฐœ์ˆ˜๋ฅผ ์„ธ์„œ ์ถœ๋ ฅํ•œ๋‹ค.

๐Ÿ”ธ end ๐Ÿ”ธ

  • ๊ฐ„๋‹จํžˆ ํ’€ ์ˆ˜ ์žˆ์—ˆ๋‹ค.

728x90

'CodingTest > Java' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

BOJ_2304 : ์ฐฝ๊ณ  ๋‹ค๊ฐํ˜•  (0) 2023.01.15
BOJ_10972 : ๋‹ค์Œ ์ˆœ์—ด  (0) 2023.01.14
BOJ_4948 : ๋ฒ ๋ฅดํŠธ๋ž‘ ๊ณต์ค€  (0) 2023.01.12
BOJ_11653 : ์†Œ์ธ์ˆ˜๋ถ„ํ•ด  (0) 2023.01.12
BOJ_10757 : ํฐ ์ˆ˜ A+B  (0) 2023.01.12