SMALL

문제는 그렇게 어렵지않으나 단순하게 for,while을 사용하면 시간초과
//이 방식은 시간초과
const fs = require('fs');
const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
let input = fs.readFileSync(filePath).toString().split(' ');
const A = +input[0];
const B = +input[1];
const V = +input[2];
solution();
function solution() {
let climb = 0;
let i = 0;
while(climb < V) {
i++;
climb += A;
if(climb >= V) {
console.log(i)
break;
} else {
climb -= B;
}
}
}
문제를 이해하고 시간을 줄여야한다.
let input = require('fs').readFileSync('/dev/stdin').toString().split(' ');
const A = +input[0];
const B = +input[1];
const V = +input[2];
solution();
function solution() {
console.log(Math.ceil((V - B) / (A - B)));
}LIST
'코테 > 코테withJS' 카테고리의 다른 글
| 백준 Node.js(자바스크립트) 1011문제 Fly me to the Alpha Centauri (0) | 2021.09.10 |
|---|---|
| 백준 Node.js(자바스크립트) 2839번 설탕배달 (0) | 2021.09.10 |
| 백준 Node.js(자바스크립트) 1712번 손익분기점 문제 (0) | 2021.08.20 |
| Node.js로 백준문제풀기 런타임에러(runtime error) (0) | 2021.08.06 |
| 백준 Node.js(자바스크립트) 2941번 크로아티아 알파벳 문제 (0) | 2021.08.05 |