๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ์ธ๊ณต๋ถ€/Algorithm

[๋ฐฑ์ค€][Node.js] 1712๋ฒˆ : ์†์ต๋ถ„๊ธฐ์ 

by ๐Ÿ‡๋ฐ•๋ด‰๋ด‰๐Ÿ‡ 2021. 7. 14.

 

 

Algorithm

-  ์†์ต๋ถ„๊ธฐ์  -

 


 

๋ฌธ์ œ

์›”๋“œ์ „์ž๋Š” ๋…ธํŠธ๋ถ์„ ์ œ์กฐํ•˜๊ณ  ํŒ๋งคํ•˜๋Š” ํšŒ์‚ฌ์ด๋‹ค. ๋…ธํŠธ๋ถ ํŒ๋งค ๋Œ€์ˆ˜์— ์ƒ๊ด€์—†์ด ๋งค๋…„ ์ž„๋Œ€๋ฃŒ, ์žฌ์‚ฐ์„ธ, ๋ณดํ—˜๋ฃŒ, ๊ธ‰์—ฌ ๋“ฑ A๋งŒ์›์˜ ๊ณ ์ • ๋น„์šฉ์ด ๋“ค๋ฉฐ, ํ•œ ๋Œ€์˜ ๋…ธํŠธ๋ถ์„ ์ƒ์‚ฐํ•˜๋Š” ๋ฐ์—๋Š” ์žฌ๋ฃŒ๋น„์™€ ์ธ๊ฑด๋น„ ๋“ฑ ์ด B๋งŒ์›์˜ ๊ฐ€๋ณ€ ๋น„์šฉ์ด ๋“ ๋‹ค๊ณ  ํ•œ๋‹ค.

 

์˜ˆ๋ฅผ ๋“ค์–ด A=1,000, B=70์ด๋ผ๊ณ  ํ•˜์ž. ์ด ๊ฒฝ์šฐ ๋…ธํŠธ๋ถ์„ ํ•œ ๋Œ€ ์ƒ์‚ฐํ•˜๋Š” ๋ฐ๋Š” ์ด 1,070๋งŒ์›์ด ๋“ค๋ฉฐ, ์—ด ๋Œ€ ์ƒ์‚ฐํ•˜๋Š” ๋ฐ๋Š” ์ด 1,700๋งŒ์›์ด ๋“ ๋‹ค.

๋…ธํŠธ๋ถ ๊ฐ€๊ฒฉ์ด C๋งŒ์›์œผ๋กœ ์ฑ…์ •๋˜์—ˆ๋‹ค๊ณ  ํ•œ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ ์ƒ์‚ฐ ๋Œ€์ˆ˜๋ฅผ ๋Š˜๋ ค ๊ฐ€๋‹ค ๋ณด๋ฉด ์–ด๋Š ์ˆœ๊ฐ„ ์ด ์ˆ˜์ž…(ํŒ๋งค๋น„์šฉ)์ด ์ด ๋น„์šฉ(=๊ณ ์ •๋น„์šฉ+๊ฐ€๋ณ€๋น„์šฉ)๋ณด๋‹ค ๋งŽ์•„์ง€๊ฒŒ ๋œ๋‹ค. ์ตœ์ดˆ๋กœ ์ด ์ˆ˜์ž…์ด ์ด ๋น„์šฉ๋ณด๋‹ค ๋งŽ์•„์ ธ ์ด์ต์ด ๋ฐœ์ƒํ•˜๋Š” ์ง€์ ์„ ์†์ต๋ถ„๊ธฐ์ ์ด๋ผ๊ณ  ํ•œ๋‹ค.

 

A, B, C๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์†์ต๋ถ„๊ธฐ์ ์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

 

๋ฌธ์ œ ํ’€๊ธฐ

let fs = require("fs");
let input = fs.readFileSync("/dev/stdin").toString().split(" ");
let a = +input[0];
let b = +input[1];
let c = +input[2];
let caculate = c - b; // c - b ๊ฐ€ 0 ์ดํ•˜์ด๋ฉด ๊ณ„์† ์ ์ž

if (caculate <= 0) console.log(-1);
else console.log(Math.floor(a / caculate) + 1);

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€