[백준/BOJ]21146. Rating Problems(C) [Bronze2]

jychan99·2021년 8월 24일
0
post-thumbnail
  1. Rating Problems

Your judges are preparing a problem set, and they’re trying to evaluate a problem for inclusion in the set. Each judge rates the problem with an integer between -3 and 3, where

3 means: I really like this problem!
-3 means: I really don’t like this problem!
0 means: Meh. I don’t care if we use this problem or not.

The overall rating of the problem is the average of all of the judges’ ratings—that is, the sum of the ratings divided by the number of judges providing a rating.
Some judges have already rated the problem. Compute the minimum and maximum possible overall rating that the problem can end up with after the other judges submit their ratings.

Input
The first line of input contains two integers n (1 <= n <= 10) and k (0 <= k <= n)where n is the total number of judges, and k is the numbers of judges who have already rated the problem.
Each of the next k line contains a single integer r (-3 <= r <= 3). These are the ratings of the k judges that have already rated the problem.

Output
two space-separated floating point numbers on a single line, which are the minimum and maximum overall rating the problem could achieve after the remaining judges rate the problem, minimum first. These values must be accurate to an absolute or relative error of 10^-4

백준 온라인 저지 그리디알고리즘 첫번째 문제이다.
뭐부터 풀어야할지 몰라서 최대한 쉬운거 정답율 100%인거부터 도전해봤다.
결과는 풀긴풀었는데 모르고 2번제출해서 정답율을 95%로 떨어뜨려놨다 ㅋㅋㅋ
그래도 풀긴풀었다.
적당히 해석해보자면...
점수를 매길건데 -3부터3까지 줄수있다.
입력으로 총 채점한횟수 n, 이미 채점된 횟수 k를 한줄에 받고,
다음줄부터는 이미 채점된 점수 r을 k개 입력받는다.
내가 주는 점수 + 이미채점된 점수로 나올수있는 최솟값, 최댓값을 출력한다.
출력할때는 최솟값 -> 최댓값순
These values must be accurate to an absolute or relative error of 10^-4
이문장은 잘은모르겠지만 10^-4 ~ 10^4(절댓값)의 범위로 출력하라는것 같음.

code

#include  <stdio.h>
int main()
{
    int n,k,r,i;
    float min=0,max=0;
    scanf("%d %d",&n,&k);
    for(i=0;i<k;i++)
    {
        scanf("%d",&r);
        max+=r;
    }
    min=max;
    min += -3*(n-k);
    max += 3*(n-k);
    printf("%f %f",min/n,max/n);
return 0;
}
  1. 평균을 내야하기 때문에 실수형 float로 선언했다.
  2. for문을 돌면서 이미 평가된 점수를 입력받는다.(k개)
  3. 입력과 동시에 max에 점수를 저장해놓고, min인덱스에 max를 복사한다.
  4. 내가 평가 할 수 있는 점수의 개수는 n-k개 이기때문에 max값에는 (n-k)3을 더해주고,
    min값에는 -3
    (n-k)을 더해준다.
  5. 총 평가 개수 n으로 나누어 평균을 구한다.
profile
내가 지금 두려워 하고 있는 일이 바로 내가 지금 해야 할 일이다. 🐥

0개의 댓글