231016 양궁대회

Jongleee·2023년 10월 16일
0

TIL

목록 보기
391/737
private int[] result;
private int[] lion;
private int maxScoreDifference;

public int[] solution(int n, int[] info) {
	result = new int[] { -1 };
	lion = new int[11];
	maxScoreDifference = 0;
	calculateOptimalLionDistribution(info, 1, n);
	return result;
}

public void calculateOptimalLionDistribution(int[] info, int count, int n) {
	if (count == n + 1) {
		int apeachPoint = 0;
		int lionPoint = 0;
		for (int i = 0; i <= 10; i++) {
			int score = 10 - i;
			if (info[i] + lion[i] != 0) {
				if (info[i] < lion[i]) {
					lionPoint += score;
				} else {
					apeachPoint += score;
				}
			}
		}
		if (isBetterDistribution(apeachPoint, lionPoint)) {
			result = lion.clone();
			maxScoreDifference = lionPoint - apeachPoint;
		}
		return;
	}
	for (int j = 0; j <= 10 && lion[j] <= info[j]; j++) {
		lion[j]++;
		calculateOptimalLionDistribution(info, count + 1, n);
		lion[j]--;
	}
}

private boolean isBetterDistribution(int apeachPoint, int lionPoint) {
	return lionPoint > apeachPoint && lionPoint - apeachPoint >= maxScoreDifference;
}

출처:https://school.programmers.co.kr/learn/courses/30/lessons/92342

0개의 댓글