https://www.acmicpc.net/problem/1546
문제
풀이
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
StringTokenizer sc = new StringTokenizer(br.readLine());
int[] score = new int[N];
int sum = 0;
for(int i = 0; i < N; i++){
score[i] = Integer.parseInt(sc.nextToken());
sum += score[i];
}
Arrays.sort(score);
System.out.println(sum * 100.0 / score[N-1] / N);
}
}
문제의 풀이를 손으로 먼저 해결해 본다면 계산식을 조금 더 단순하게 구하기 쉽다고 생각한다.
분배법칙을 역으로 이용해 공통인수를 묶을 수 있어 해결이 쉬웠다.
'문제 풀이 > 백준' 카테고리의 다른 글
[백준] 2018번. 수 들의 합5 (0) | 2024.01.28 |
---|---|
[백준] 11659번. 구간 합 구하기 4 (JAVA) (1) | 2024.01.28 |
[백준] 11720번. 숫자의 합(JAVA) (1) | 2024.01.28 |
[백준] 13164번. 행복 유치원(JAVA) (0) | 2024.01.17 |
[백준] 1758번. 알바생 강호(JAVA) (0) | 2024.01.16 |