๋ฐฑ์ค€ 20546 - ๐Ÿœ ๊ธฐ์ ์˜ ๋งค๋งค๋ฒ• ๐Ÿœ

Updated:

Java

20546 ๋ฒˆ - ๐Ÿœ ๊ธฐ์ ์˜ ๋งค๋งค๋ฒ• ๐Ÿœ

๋ฌธ์ œ

์ ‘๊ทผ ๋ฐฉ๋ฒ•

3์ผ ์—ฐ์† ๊ฐ€๊ฒฉ์ด ์ „์ผ ๋Œ€๋น„ ์ƒ์Šน / ํ•˜๋ฝ์˜ ์˜๋ฏธ๊ฐ€ ๋ชจํ˜ธํ•ด์„œ ๊ณ ๋ฏผ์„ ์กฐ๊ธˆ ํ–ˆ๋˜ ๋ฌธ์ œ์ด๋‹ค.
๊ฒฐ๋ก ์€, ์˜ค๋Š˜(n) ๊ธฐ์ค€ 3์ผ ์ „๋ถ€ํ„ฐ ๊ฐ€๊ฒฉ์˜ ์ƒ์Šน or ํ•˜๋ฝ์„ ํ™•์ธํ•˜๋ฉด ๋œ๋‹ค.

if(i >= 3) {
	// ์ฃผ๊ฐ€๊ฐ€ ์ƒ์Šนํ•œ๋‹ค๋ฉด
	if(arr[i - 1] > arr[i - 2] && arr[i - 2] > arr[i - 3]) {
		// ์ „๋Ÿ‰ ๋งค๋„
	}

	// ์ฃผ๊ฐ€๊ฐ€ ํ•˜๋ฝํ•œ๋‹ค๋ฉด
	if(arr[i - 1] < arr[i - 2] && arr[i - 2] < arr[i - 3]) {
		// ์ „๋Ÿ‰ ๋งค์ˆ˜
	}
}

์ฝ”๋“œ

import java.util.*;
import java.io.*;

public class Main {
	static int n, result;

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

    	int bMoney = n;
    	int tMoney = n;
    	int bCnt = 0;
    	int tCnt = 0;

    	int[] arr = new int[14];
    	int cnt;
    	stk = new StringTokenizer(br.readLine());
    	for(int i = 0; i < 14; i++) {
    		arr[i] = stoi(stk.nextToken());
    	}

    	int upDown = 0;
    	for(int i = 0; i < 14; i++) {
    		// ์ค€ํ˜„์ด
    		if(arr[i] <= bMoney) {
    			cnt = bMoney / arr[i];
    			bMoney -= cnt * arr[i];
    			bCnt += cnt;
    		}

    		// ์„ฑ๋ฏผ์ด
    		if(i >= 3) {
    			// ์ฃผ๊ฐ€๊ฐ€ ์ƒ์Šนํ•œ๋‹ค๋ฉด
    			if(arr[i - 1] > arr[i - 2] && arr[i - 2] > arr[i - 3]) {
    				tMoney += tCnt * arr[i];		// ์ „๋Ÿ‰ ๋งค๋„
    				tCnt = 0;
    			}

    			// ์ฃผ๊ฐ€๊ฐ€ ํ•˜๋ฝํ•œ๋‹ค๋ฉด
    			if(arr[i - 1] < arr[i - 2] && arr[i - 2] < arr[i - 3]) {
    				cnt = tMoney / arr[i];		// ์ „๋Ÿ‰ ๋งค์ˆ˜
    				tMoney -= cnt * arr[i];
    				tCnt += cnt;
    			}
    		}
    	}

    	int bSum = bMoney + bCnt * arr[13];
    	int tSum = tMoney + tCnt * arr[13];
    	//System.out.println(bSum + " " + tSum);
    	if(bSum > tSum) {
    		System.out.println("BNP");
    	}
    	else if(bSum < tSum) {
    		System.out.println("TIMING");
    	}
    	else {
    		System.out.println("SAMESAME");
    	}

    	br.close();
	}

	static int stoi(String str) {
    	return Integer.parseInt(str);
    }
}