[BOJ] 2484번: 주사위 네개

김주원·2020년 8월 6일
0
post-thumbnail

문제 링크

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

코드

C++

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N;
vector<int> result;
int a, b;

// 문제의 조건중 어느 번호 조건에 해당하는지 판별
int f(int cnt[]) {
	vector<int> temp;
	
	for (int i = 1; i <= 6; i++) {
		if (cnt[i] > 0)
			temp.push_back(i);
		
		// 같은 눈이 4개가 나오면
		if (cnt[i] == 4) {
			a = i;
			return 1;
		}
		// 같은 눈이 3개가 나오면
		else if (cnt[i] == 3) {
			a = i;
			return 2;
		}
		// 같은 눈이 2개가 나오는 경우
		else if (cnt[i] == 2) {
			for (int j = i + 1; j <= 6; j++) {
				// 같은 눈이 2개씩 두 쌍이 나오면
				if (cnt[j] == 2) {
					a = i;
					b = j;
					return 3;
				}
			}
			// 같은 눈이 2개만 나오는 경우
			a = i;
			return 4;
		}
	}
	// 모두 다른 눈이 나오면
	sort(temp.begin(), temp.end());
	a = temp[temp.size() - 1];
	return 5;
}

int main() {
	scanf("%d", &N);
	result.resize(N);

	for (int i = 0; i < N; i++) {
		// 주사위 번호(1 ~ 6)당 얼마나 나왔는지 카운트하는 배열
		int cnt[7] = { 0 };

		int dice[4];

		for (int j = 0; j < 4; j++) {
			scanf("%d", &dice[j]);
			cnt[dice[j]]++;
		}

		int condition = f(cnt);

		if (condition == 1)
			result[i] = 50000 + a * 5000;
		else if (condition == 2)
			result[i] = 10000 + a * 1000;
		else if (condition == 3)
			result[i] = 2000 + a * 500 + b * 500;
		else if (condition == 4)
			result[i] = 1000 + a * 100;
		else
			result[i] = a * 100;
	}

	sort(result.begin(), result.end());

	printf("%d\n", result[N - 1]);

	return 0;
}
profile
자기계발 블로그

0개의 댓글