๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algoritm/Quiz-Solutions

[๋ฐฑ์ค€ 15953] ์ƒ๊ธˆํ—Œํ„ฐ (JAVA)

by ๐Ÿ’œautumn 2020. 5. 2.

[๋ฌธ์ œ๋งํฌ]

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

 

15953๋ฒˆ: ์ƒ๊ธˆ ํ—Œํ„ฐ

์ฒซ ๋ฒˆ์งธ ์ค„์— ์ œ์ด์ง€๊ฐ€ ์ƒ์ƒ๋ ฅ์„ ๋ฐœํœ˜ํ•˜์—ฌ ๊ฐ€์ •ํ•œ ํšŸ์ˆ˜ T(1 ≤ T ≤ 1,000)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ T๊ฐœ ์ค„์—๋Š” ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ œ์ด์ง€๊ฐ€ ํ•ด๋ณธ ๊ฐ€์ •์— ๋Œ€ํ•œ ์ •๋ณด๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๊ฐ ์ค„์—๋Š” ๋‘ ๊ฐœ์˜ ์Œ์ด ์•„๋‹Œ ์ •์ˆ˜ a(0 ≤ a ≤ 100)์™€ b(0 ≤ b ≤ 64)๊ฐ€ ๊ณต๋ฐฑ ํ•˜๋‚˜๋ฅผ ์‚ฌ์ด๋กœ ๋‘๊ณ  ์ฃผ์–ด์ง„๋‹ค.

www.acmicpc.net

 

[ํ’€์ด์†Œ์Šค]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package Algorithm;
 
 
public class KakaoFestival {
    public static int[] prize2017= {500,300,200,50,30,10};
    public static int[] prize2018= {512,256,128,64,32};
    
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=null;
        StringBuilder sb=new StringBuilder();
        
        int testcase=Integer.parseInt(br.readLine());
        
        for (int i=0;i<testcase;i++) {
            st=new StringTokenizer(br.readLine());
            int rank2017=Integer.parseInt(st.nextToken());
            int rank2018=Integer.parseInt(st.nextToken());
            
            int total=calcPrize(rank2017, rank2018);
            
            sb.append(total+"\n");
        }
        
        System.out.println(sb);
    }
    
    public static int calcPrize(int rank2017, int rank2018) {
        int reward2017=0;
        int reward2018=0;s
        int total=0;
        
        if (rank2017>0 && rank2017<22) {
            for(int i=1; i<=6; i++) {
                rank2017-=i;
                if((rank2017)<=0) {
                    reward2017=prize2017[i-1];
                }
                if (reward2017!=0break;
            }
        }
        
        if (rank2018>0 && rank2018<32) {
            for(int i=0; i<=4; i++) {
                rank2018-=Math.pow(2, i);
                if(rank2018<=0) {
                    reward2018=prize2018[i];
                }
                if (reward2018!=0break;
            }
        }
        total=reward2017+reward2018;
        return total*10000;
    }
    
 
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter

 

[๋Š๋‚€์ ]

  - ์ž…๋ ฅ์ฒ˜๋ฆฌ ๊ณต๋ถ€ 

  - ์žฌ๊ท€ํ•จ์ˆ˜ ์‚ฌ์šฉ

  - ์กฐ๊ฑด๋ฌธ์ด ๋„ˆ๋ฌด ๋งŽ์€๊ฒƒ๊ฐ™์Œ

  - ๋‹ค๋ฅธ์‚ฌ๋žŒ๋“ค์ด ํ’€์ดํ•œ๊ฑธ ๋ณด๋‹ˆ ๋ฐฐ์—ด๋กœ ๋ชจ๋“  ๊ฐ’๋“ค์„ ํ™œ์šฉํ•˜๋Š”๊ฒƒ์ด ๋งŽ์•˜์Œ

     → ๋‚˜๋Š” ๊ทœ์น™์„ ์ฐพ์•„ ๊ทธ ๊ฐ’์„ ๊ผญ ๋งŒ๋“ค์–ด๋‚ด๋ ค๊ณ  ํ•˜๋Š”๋ฐ, 

        ์‹œ๊ฐ„์ ˆ์•ฝ์„ ์œ„ํ•ด์„œ ์•ž์œผ๋กœ๋Š” ๊ตณ์ด ๊ทธ๋Ÿด ํ•„์š”๊ฐ€ ์—†๋‹ค๋Š” ๊ฒƒ!

 

 

๋Œ“๊ธ€