작성일 :

문제 링크

3733번 - Shares

설명

N명과 심판 1명이 S개의 주식을 똑같이 나눌 때, 각 사람이 받을 수 있는 최대 주식 수를 구하는 문제입니다.


접근법

총 인원은 N명에 심판 1명을 더한 N + 1명입니다.

따라서 S를 N + 1로 나눈 몫이 각 사람이 받을 수 있는 최대 주식 수입니다.

입력이 EOF까지 주어지므로 각 줄마다 반복 처리합니다.



Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
namespace Solution {
  class Program {
    static void Main(string[] args) {

      while (true) {
        string[]? input = Console.ReadLine()?.Split();
        if (input == null) break ;
        int.TryParse(input?[0], out int n);
        int.TryParse(input?[1], out int cntP);
        n++;
        Console.WriteLine(cntP / n);
      }
    }
  }
}

C++

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

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

  int n, s;
  while (cin >> n >> s)
    cout << s / (n + 1) << "\n";

  return 0;
}