작성일 :

문제 링크

21339번 - Contest Struggles

설명

문제 세트의 전체 평균 난이도와 이미 푼 문제들의 평균 난이도가 주어질 때, 남은 문제들의 평균 난이도를 계산하거나 범위를 벗어나면 impossible을 출력하는 문제입니다.


접근법

전체 문제 수와 전체 평균, 푼 문제 수와 푼 문제의 평균이 주어집니다. 전체 난이도 합에서 푼 문제의 난이도 합을 빼면 남은 문제의 난이도 합이 됩니다. 이를 남은 문제 수로 나누면 남은 문제의 평균을 구할 수 있습니다.

계산된 평균이 0 이상 100 이하이면 출력하고, 범위를 벗어나면 impossible을 출력합니다.


Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using System;

class Program {
  static void Main() {
    var first = Console.ReadLine()!.Split();
    var n = int.Parse(first[0]);
    var k = int.Parse(first[1]);

    var second = Console.ReadLine()!.Split();
    var d = int.Parse(second[0]);
    var s = int.Parse(second[1]);

    var x = (n * d - k * s) / (double)(n - k);
    if (x < -1e-9 || x > 100 + 1e-9) Console.WriteLine("impossible");
    else Console.WriteLine(x.ToString("0.##########"));
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k; cin >> n >> k;
  int d, s; cin >> d >> s;

  double x = (n * d - k * s) / double(n - k);
  if (x < -1e-9 || x > 100.0 + 1e-9) cout << "impossible\n";
  else cout << fixed << setprecision(10) << x << "\n";

  return 0;
}