
BOJ 1009 분산처리
2023-05-25
1 min
땅 위에 달팽이가 있다. 이 달팽이는 높이가 V미터인 나무 막대를 올라갈 것이다.
달팽이는 낮에 A미터 올라갈 수 있다. 하지만, 밤에 잠을 자는 동안 B미터 미끄러진다. 또, 정상에 올라간 후에는 미끄러지지 않는다.
달팽이가 나무 막대를 모두 올라가려면, 며칠이 걸리는지 구하는 프로그램을 작성하시오.
첫째 줄에 세 정수 A, B, V가 공백으로 구분되어서 주어진다. (1 ≤ B < A ≤ V ≤ 1,000,000,000)
해당 문제는 달팽이가 나무를 모두 올라가는 데 걸리는 일수를 구하는 문제로 사칙 연산 문제이다.
달팽이가 하루에 올라갈 수 있는 높이는 낮에 올라가는 높이에서 밤에 미끄러지는 높이를 뺀 값인 (A - B)이다.
또한 정상에 올라간 후에는 미끄러지지 않는다고 하였으므로 달팽이가 올라가야 하는 높이는 나무 막대의 높이에서 미끄러지는 높이를 뺀 값인 (C - B)이다.
따라서 달팽이가 나무 막대를 모두 올라가는데 며칠이 걸리는지 알기 위해서는 (C - B) / (A - B)를 계산해 올림하면 된다.
import java.io.*;
public class Main{
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s = br.readLine().split(" ");
double a = Double.parseDouble(s[0]);
double b = Double.parseDouble(s[1]);
double c = Double.parseDouble(s[2]);
System.out.println((int)Math.ceil((c - b) / (a - b)));
}
}
#include <iostream>
#include <cmath>
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define endl '\n'
using namespace std;
int main() {
fastio;
double a, b, c;
cin >> a >> b >> c;
std::cout<<fixed;
cout.precision(0);
cout << ceil((c - b) / (a - b)) << endl;
return 0;
}
import kotlin.math.*
fun main(args: Array<String>) = with(System.`in`.bufferedReader()) {
var s = readLine().split(" ")
var a: Double = s[0].toDouble()
val b: Double = s[1].toDouble()
val c: Double = s[2].toDouble()
println(ceil((c - b) / (a - b)).toInt())
}
from sys import stdin
import math
def main():
s = stdin.readline().split(' ')
a = int(s[0])
b = int(s[1])
c = int(s[2])
print(math.ceil((c - b) / (a - b)))
if __name__ == "__main__":
main()
import Foundation
func main() {
var s = readLine()!.split(separator: " ")
var a = Double(s[0])!
var b = Double(s[1])!
var c = Double(s[2])!
print(Int(ceil((c - b) / (a - b))))
}
main()
