치춘짱베리굿나이스

[백준] 3733 본문

Shares

문제

A group of N persons and the ACM Chief Judge share equally a number of S shares (not necessary all of them). Let x be the number of shares aquired by each person (x must be an integer). The problem is to compute the maximum value of x.

Write a program that reads pairs of integer numbers from an input text file. Each pair contains the values of 1 ≤ N ≤ 10000 and 1 ≤ S ≤ 109 in that order. The input data are separated freely by white spaces, are correct, and terminate with an end of file. For each pair of numbers the program computes the maximum value of x and prints that value on the standard output from the beginning of a line, as shown in the example below.

풀이

const shares = () => {
  let input = require("fs")
    .readFileSync("/dev/stdin")
    .toString()
    .trim()
    .split("\n")
    .map((v) => v.split(" ").map(Number));
  let arr = [];
  for (let v of input) arr.push(Math.floor(v[1] / (v[0] + 1)));
  console.log(arr.join("\n"));
};

shares();

반성회

입력, 출력 소제목이 없다

N명의 사람들이랑 ACM 대장이 값을 나눠가져야 하므로 v[0] + 1로 나눠주면 된다

'Javascript + Typescript > 자바스크립트로 알고리즘풀기' 카테고리의 다른 글

[백준] 18096  (0) 2022.07.14
[백준] 17256  (0) 2022.07.13
[백준] 2754  (0) 2022.07.13
[백준] 6064  (0) 2022.07.12
[백준] 1205  (0) 2022.07.11
Comments