알고리즘/백준알고리즘

[백준알고리즘] #18301. Rats (by JAVA and node.js)

Jimnya 2022. 4. 14. 14:32
728x90
반응형

백준알고리즘

- Bronze 5 -

 #18301. Rats by JAVA and node.js 

 


 

문제

출처: https://www.acmicpc.net/problem/18301 

 

해석본: https://www.acmicpc.net/board/view/85431

 

글 읽기 - (번역) 18301 - 쥐

댓글을 작성하려면 로그인해야 합니다.

www.acmicpc.net

 


 

접근 방법

번역(해석)본을 보면 문제 자체는 어렵지 않다.

다만 조심해야 할 부분은 where ⌊x⌋ is the floor of a real number x, i.e., the closest integer less than or equal to x. 부분이다.

 


 

풀이

▶ JAVA

import java.util.*;

public class Main {
    public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	int n1 = scan.nextInt();
    	int n2 = scan.nextInt();
    	int n12 = scan.nextInt();
    	scan.close();
    	System.out.println(((n1 + 1)*(n2 + 1)/(n12 + 1)) - 1);
    }
}

▶ node.js

var fs = require('fs');
var input = fs.readFileSync('/dev/stdin').toString().trim().split(' ').map(v => +v);
var n1 = input[0];
var n2 = input[1];
var n12 = input[2];
var answer = parseInt(((n1 + 1)*(n2 + 1)/(n12 + 1)) - 1);

console.log(answer);

 


 

결과

 


 

 

 

 

 

End.

heisely's 괴발개발 개발일지

 

728x90
반응형