01-09 18:44
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

[BAEKJOON] ๋ฐฑ์ค€ ๊ทธ๋ฆฌ๋”” 11047 :: ๋™์ „ 0 JAVA ๋ณธ๋ฌธ

Algorithm/Baekjoon

[BAEKJOON] ๋ฐฑ์ค€ ๊ทธ๋ฆฌ๋”” 11047 :: ๋™์ „ 0 JAVA

miinsun 2022. 3. 16. 16:16

 

๐Ÿ’ฌ  ๋ฌธ์ œ ์„ค๋ช…

์ค€๊ทœ๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋™์ „์€ ์ด N์ข…๋ฅ˜์ด๊ณ , ๊ฐ๊ฐ์˜ ๋™์ „์„ ๋งค์šฐ ๋งŽ์ด ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.

๋™์ „์„ ์ ์ ˆํžˆ ์‚ฌ์šฉํ•ด์„œ ๊ทธ ๊ฐ€์น˜์˜ ํ•ฉ์„ K๋กœ ๋งŒ๋“ค๋ ค๊ณ  ํ•œ๋‹ค.
์ด๋•Œ ํ•„์š”ํ•œ ๋™์ „ ๊ฐœ์ˆ˜์˜ ์ตœ์†Ÿ๊ฐ’์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

๐Ÿ”จ  ์ž…์ถœ๋ ฅ ์˜ˆ

์ž…๋ ฅ 

  • ์ฒซ์งธ ์ค„์— N๊ณผ K๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ N ≤ 10, 1 ≤ K ≤ 100,000,000)
  • ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ๋™์ „์˜ ๊ฐ€์น˜ Ai๊ฐ€ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ Ai ≤ 1,000,000, A1 = 1, i ≥ 2์ธ ๊ฒฝ์šฐ์— Ai๋Š” Ai-1์˜ ๋ฐฐ์ˆ˜)
 

์ถœ๋ ฅ

  • ์ฒซ์งธ ์ค„์— K์›์„ ๋งŒ๋“œ๋Š”๋ฐ ํ•„์š”ํ•œ ๋™์ „ ๊ฐœ์ˆ˜์˜ ์ตœ์†Ÿ๊ฐ’์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ 1)

10 4200
1
5
10
50
100
500
1000
5000
10000
50000

 

์˜ˆ์ œ ์ถœ๋ ฅ 1)

6

 

์˜ˆ์ œ ์ž…๋ ฅ 2)

10 4790
1
5
10
50
100
500
1000
5000
10000
50000

 

์˜ˆ์ œ ์ถœ๋ ฅ 2)

12

โ€‹

๐Ÿ’ป  Main.java

  • ๊ทธ๋ฆฌ๋”” ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ๊ฐ ์„ ํƒ์—์„œ ์ตœ์„ ์˜ ๋ฐฉ์‹์„ ์„ ํƒํ•จ
  • ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ๋Š” ๊ฐ€์žฅ ํฐ ์ˆ˜ ๋ถ€ํ„ฐ ๋‚˜๋ˆ ๊ฐ€๋ฉด์„œ ๋™์ „์˜ ์ˆ˜๋ฅผ ์„ผ๋‹ค.
  • ์˜ˆ๋ฅผ ๋“ค์–ด 12300์›์ด ์žˆ์œผ๋ฉด, 10000์›์œผ๋กœ ๋‚˜๋ˆ  ๋ชซ 1 ๋‚˜๋จธ์ง€ 2300์ด ์ƒ๊ธด๋‹ค. 1์ด ๋™์ „์˜ ๊ฐฏ์ˆ˜์ด๊ณ , ์ž”์•ก 2300์›์„ ๋‹ค์‹œ ๋‚˜๋ˆ ์ฃผ์ž.
/* ๋ฐฑ์ค€ ๊ทธ๋ฆฌ๋”” - 11047 :: ๋™์ „ 0 */
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// n๊ฐœ์˜ ๋™์ „ ์ข…๋ฅ˜, k์›์„ ๋งŒ๋“ค์ž
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] coins = new int[n];
		for(int i = 0; i < n; i++) {
			coins[i] = sc.nextInt();
		}
		
		int answer = 0;
		for(int i = n - 1; i >= 0; i--) {
			if(coins[i] <= k) {
				answer += (k / coins[i]);
				k = k % coins[i];
			}
		}
		
		System.out.println(answer);
		sc.close();
	}
}
Comments