fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
백준 29753 (C++) 최소 성적
최초 업로드: 2025-09-26 08:44:29
최근 수정 시간: 2025-09-26 08:44:29
게시자: rlatjwls3333
카테고리: 백준
조회수: 18
# [Silver IV] 최소 성적 [문제 링크](https://www.acmicpc.net/problem/29753) ## 문제 설명 <p>이번 학기에 받아야 하는 최소 평균 평점 기준과 수강한 과목 중 한 과목을 제외한 모든 과목의 성적이 주어졌을 때, 최소 평균 평점 기준을 충족하기 위해 받아야 하는 나머지 한 과목의 최소 성적을 출력하시오. 성적에 따른 평점 환산표는 다음과 같다.</p> <div style="overflow:auto;max-width:calc(100vw - 30px)"> <table align="center" border="1" cellpadding="1" cellspacing="1" class="table table-bordered" style="table-layout: fixed; text-align: center; width: 600px; height: 60px;"> <tbody> <tr> <th scope="row" style="text-align: center; width: 75px;">성적</th> <td style="text-align: center; width: 50px;">A+</td> <td style="text-align: center; width: 50px;">A0</td> <td style="text-align: center; width: 50px;">B+</td> <td style="text-align: center; width: 50px;">B0</td> <td style="text-align: center; width: 50px;">C+</td> <td style="text-align: center; width: 50px;">C0</td> <td style="text-align: center; width: 50px;">D+</td> <td style="text-align: center; width: 50px;">D0</td> <td style="text-align: center; width: 50px;">F</td> </tr> <tr> <th scope="row" style="text-align: center; width: 75px;">평점</th> <td style="text-align: center; width: 50px;">4.50</td> <td style="text-align: center; width: 50px;">4.00</td> <td style="text-align: center; width: 50px;">3.50</td> <td style="text-align: center; width: 50px;">3.00</td> <td style="text-align: center; width: 50px;">2.50</td> <td style="text-align: center; width: 50px;">2.00</td> <td style="text-align: center; width: 50px;">1.50</td> <td style="text-align: center; width: 50px;">1.00</td> <td style="text-align: center; width: 50px;">0.00</td> </tr> </tbody> </table> </div> <p>이번 학기의 평균 평점은 $($과목별 $($학점 $\times$ 평점$)$의 합 $\div$ 이번 학기에 수강한 과목의 학점 총합$)$을 소수점 이하 세 번째 자리에서 버림한 값이며, 이번 학기의 평균 평점이 최소 평균 평점 기준을 <strong>초과</strong>하는 경우 최소 평균 평점 기준을 충족한 것으로 인정된다. <strong>단, 실수 자료형을 사용할 경우 부동 소수점 오차가 발생할 수 있으므로 주의하라.</strong></p> ## 입력 <p>첫 번째 줄에 이번 학기에 수강한 과목 수 $N$과 이번 학기에 받아야 하는 최소 평균 평점 기준 $X$가 공백으로 구분되어 주어진다. $(2 \le N \le 24;$ $0.00 \le X \le 4.50;$ $X$는 소수점 이하 두 자리까지 주어지는 실수$)$</p> <p>두 번째 줄부터 $N - 1$개의 줄에 걸쳐 각 과목의 학점 $c_i$와 성적 $g_i$가 공백으로 구분되어 주어진다. $(1 \le c_i \le 6;$ $g_i$는 <span style="color:#e74c3c;"><code>A+</code></span>, <span style="color:#e74c3c;"><code>A0</code></span>, <span style="color:#e74c3c;"><code>B+</code></span>, <span style="color:#e74c3c;"><code>B0</code></span>, <span style="color:#e74c3c;"><code>C+</code></span>, <span style="color:#e74c3c;"><code>C0</code></span>, <span style="color:#e74c3c;"><code>D+</code></span>, <span style="color:#e74c3c;"><code>D0</code></span>, <span style="color:#e74c3c;"><code>F</code></span>중 하나$)$</p> <p>그다음 줄에는 나머지 한 과목의 학점 $L$이 주어진다. $(1 \le L\le 6)$</p> ## 출력 <p>최소 평균 평점 기준을 충족하기 위해 받아야 하는 나머지 한 과목의 최소 성적을 출력한다. 만약 어떤 성적을 받아도 최소 평균 평점 기준을 충족할 수 없다면 "<span style="color:#e74c3c;"><code>impossible</code></span>"을 출력한다.</p> ## 풀이 실수 오차를 다루는 방법을 배울 수 있는 좋은 문제입니다. - 방법 1. 실수 -> 정수로 변경하여 다루기. - 방법 2. 실수 -> 문자열로 변경하여 다루기. - 방법 3. 실수 오차만큼 추가로 더해주기. ``` c++ #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; ld tmp; cin >> n >> tmp; ll x = tmp*100+0.00000001, w=0, total=0; while(n-->1) { ll c; string g; cin >> c >> g; w += c; if(g=="A+") total += c*450; else if(g=="A0") total += c*400; else if(g=="B+") total += c*350; else if(g=="B0") total += c*300; else if(g=="C+") total += c*250; else if(g=="C0") total += c*200; else if(g=="D+") total += c*150; else if(g=="D0") total += c*100; } ll l; cin >> l; w += l; ll need = x*w-total+w; if(need<=0) cout << "F"; else if(need<=l*100) cout << "D0"; else if(need<=l*150) cout << "D+"; else if(need<=l*200) cout << "C0"; else if(need<=l*250) cout << "C+"; else if(need<=l*300) cout << "B0"; else if(need<=l*350) cout << "B+"; else if(need<=l*400) cout << "A0"; else if(need<=l*450) cout << "A+"; else cout << "impossible"; } ```