Algorithm/baekjoon

기적의 매매법

마닐라 2022. 3. 3. 13:58

📍 문제 설명

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

 

20546번: 🐜 기적의 매매법 🐜

1월 14일 기준 준현이의 자산이 더 크다면 "BNP"를, 성민이의 자산이 더 크다면 "TIMING"을 출력한다. 둘의 자산이 같다면 "SAMESAME"을 출력한다. 모든 결과 따옴표를 제외하고 출력한다.

www.acmicpc.net

 

💡 접근

조건별로 주식량을 구하면 되는 문제.

성민이의 매수/매도 방식이 3일로만 고정되어 있어 따로 변수를 사용하지 않았다.

 

👩‍💻 코드

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

public class Main {
    static int n, m, v, e, k, r, t, answer, cnt, sum, max = Integer.MIN_VALUE, min = Integer.MAX_VALUE, firstX, firstY;
    static int[] arr, dx = {1,0,-1,0}, dy = {0,-1,0,1};
    static long[] dp;
    static int[][] board, clone, nearEmptySeatCnt;
    static boolean[][] visited;
    static ArrayList<Integer> list;
    static HashMap<Integer, ArrayList> map;
    static TreeSet<Character> set;
    static StringBuilder sb;
    static StringTokenizer st;

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

        n = Integer.parseInt(br.readLine());
        arr = new int[15];
        st = new StringTokenizer(br.readLine());
        for(int i = 1; i <= 14; i++) {
            arr[i] = Integer.parseInt(st.nextToken());
        }

        //준현이의 보유 주식 수
        int junhyunStockCnt = 0;
        int sungminStockcnt = 0;

        int tmp = n;

        //준현이의 주식 사기
        for(int i = 1; i <= 14; i++) {
            //매수 가능 주식 수
            int possibleBuyStockCnt = tmp / arr[i];
            junhyunStockCnt += possibleBuyStockCnt;
            tmp -= arr[i] * possibleBuyStockCnt;
        }
        int assetsOfJunhyun = tmp + junhyunStockCnt * arr[14];

        tmp = n;
        for(int i = 4; i <= 14; i++) {
            //3일 연속 가격 하락하면 전액 매수
            if(arr[i-3] > arr[i-2] && arr[i-2] > arr[i-1] && arr[i-1] > arr[i]) {
                //매수 가능 주식 수
                int possibleBuyStockCnt = tmp / arr[i];
                sungminStockcnt += possibleBuyStockCnt;
                tmp -= arr[i] * possibleBuyStockCnt;
            }
            if(arr[i-3] < arr[i-2] && arr[i-2] < arr[i-1] && arr[i-1] < arr[i]) {
                tmp += arr[i] * sungminStockcnt;
                sungminStockcnt = 0;
            }
        }
        int assetsOfSungmin = tmp + sungminStockcnt * arr[14];

        if(assetsOfJunhyun > assetsOfSungmin) System.out.println("BNP");
        else if(assetsOfJunhyun < assetsOfSungmin) System.out.println("TIMING");
        else System.out.println("SAMESAME");
    }


    private void solution() {

    }


}

'Algorithm > baekjoon' 카테고리의 다른 글

빙고  (0) 2022.03.03
소가 길을 건너간 이유 1  (0) 2022.03.03
상어 초등학교  (0) 2022.03.02
스택 수열  (0) 2022.03.02
Two Dots=========  (0) 2022.03.02