๊ธฐ๋ก๋ฐฉ

BOJ_1049 : ๊ธฐํƒ€์ค„ ๋ณธ๋ฌธ

CodingTest/Java

BOJ_1049 : ๊ธฐํƒ€์ค„

Soom_1n 2022. 10. 19. 17:43

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

 

1049๋ฒˆ: ๊ธฐํƒ€์ค„

์ฒซ์งธ ์ค„์— N๊ณผ M์ด ์ฃผ์–ด์ง„๋‹ค. N์€ 100๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๊ณ , M์€ 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ M๊ฐœ์˜ ์ค„์—๋Š” ๊ฐ ๋ธŒ๋žœ๋“œ์˜ ํŒจํ‚ค์ง€ ๊ฐ€๊ฒฉ๊ณผ ๋‚ฑ๊ฐœ์˜ ๊ฐ€๊ฒฉ์ด ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•˜์—ฌ ์ฃผ

www.acmicpc.net



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

  • ๋Š์–ด์ง„ ๊ธฐํƒ€์ค„์˜ ์ˆ˜ n, ๊ธฐํƒ€์ค„ ๋ธŒ๋žœ๋“œ์˜ ์ˆ˜ m์ด ์ž…๋ ฅ๋œ๋‹ค.
    • ๊ธฐํƒ€์ค„ ๋ธŒ๋žœ๋“œ ์ˆ˜ m๋งŒํผ, 6ํŒฉ ๊ฐ€๊ฒฉ๊ณผ ๋‚ฑ๊ฐœ ๊ฐ€๊ฒฉ์ด ์ž…๋ ฅ๋œ๋‹ค.
  • n๊ฐœ์˜ ๊ธฐํƒ€์ค„์„ ์‚ฌ๋Š”๋ฐ ๊ฐ€์žฅ ์ €๋ ดํ•œ ๊ฐ€๊ฒฉ์„ ์ถœ๋ ฅํ•œ๋‹ค.
    • ์ดˆ๊ณผ๋กœ ์‚ฌ๋”๋ผ๋„ ์‹ธ๊ธฐ๋งŒ ํ•˜๋ฉด ๋œ๋‹ค.

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

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

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

        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());

        int min_pack = 1000;
        int min = 1000;
        for (int i = 0; i < m; i++){
            st = new StringTokenizer(br.readLine());
            int pack = Integer.parseInt(st.nextToken());
            int one = Integer.parseInt(st.nextToken());
            if (pack < min_pack) min_pack = pack;
            if (one < min) min = one;
        }

        int answer = 0;
        answer += min * 6 < min_pack ? (n/6) * (6 * min) : n/6 * min_pack;
        answer += min * (n%6) < min_pack ? min * (n%6) : min_pack;
        System.out.println(answer);
    }
}

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

  • n๊ณผ m์„ ์ž…๋ ฅ๋ฐ›๊ณ , m๋งŒํผ ๋ฐ˜๋ณตํ•ด์„œ ์ž…๋ ฅ๋ฐ›์œผ๋ฉฐ ํŒฉ๊ณผ ๋‚ฑ๊ฐœ ๊ฐ€๊ฒฉ์˜ ์ตœ์†Œ๊ฐ’์„ ๊ตฌํ•œ๋‹ค.
    • ํŒฉ๊ณผ ๋‚ฑ๊ฐœ์˜ ์ตœ๋Œ€๊ฐ’์€ 1000์œผ๋กœ ๋ฌธ์ œ์— ์ฃผ์–ด์กŒ์œผ๋ฏ€๋กœ, ์ดˆ๊ธฐ๊ฐ’์œผ๋กœ ์ž…๋ ฅํ•ด๋‘”๋‹ค.
  • 6๊ฐœ๋ฅผ ๊ตฌ๋งคํ•˜๋Š”๋ฐ ํŒฉ์ด๋” ์‹ผ์ง€ ๋‚ฑ๊ฐœ6๊ฐœ ๊ฐ€ ๋” ์‹ผ์ง€ ๊ณ„์‚ฐํ•œ๋‹ค.
    • ๋” ์‹ผ ๊ฐ€๊ฒฉ์œผ๋กœ n/6๋ฒˆ ๊ตฌ๋งคํ•œ๋‹ค.
  • ๋‚จ์€ n%6๊ฐœ๋Š” ์ดˆ๊ณผํ•ด์„œ ์‚ฌ๋”๋ผ๋„ ํŒฉ์œผ๋กœ ์‚ฌ๋Š”๊ฒŒ ๋” ์Œ€ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ, ๋น„๊ตํ•ด์„œ ๊ตฌ๋งคํ•œ๋‹ค.
  • ์ด ๊ตฌ๋งค๊ฐ€๊ฒฉ์„ ์ถœ๋ ฅํ•œ๋‹ค.

๐Ÿ”ธ end ๐Ÿ”ธ

  • ๊ฐ„๋‹จํ•œ ๋ฌธ์ œ์˜€์ง€๋งŒ ์ดˆ๊ณผํ•ด์„œ ํŒฉ์œผ๋กœ ์‚ฌ๋Š”๊ฒŒ ๋” ์‹ผ ๊ฒฝ์šฐ๋ฅผ ๋’ค๋Šฆ๊ฒŒ ๊นจ๋‹ซ๊ณ  ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ–ˆ๋‹ค.

728x90