main
[백준-2869번/Java] 달팽이는 올라가고 싶다. 본문
* 감으로 품(왜 맞는지 생각해봐야 함)
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int A = sc.nextInt();
int B = sc.nextInt();
int V = sc.nextInt();
int record = 0;
int day = 0;
System.out.println((int) Math.ceil((double) (V - A) / (A - B)) + 1);
}
}
* 시간 초과
* 반복문으로 작성하면 시간 초과 난다.
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int A = sc.nextInt();
int B = sc.nextInt();
int V = sc.nextInt();
int record = 0;
int day = 0;
while (true) {
day++;
record += A;
if (record >= V) {
System.out.println(day);
break;
}
record -= B;
}
}
}
728x90
'Algorithm' 카테고리의 다른 글
[백준-1920번/Java] 수 찾기 (0) | 2022.11.11 |
---|---|
[백준-2839번/Java] 설탕배달 (0) | 2022.11.11 |
[백준-2751번/Java] 수 정렬하기 2 (0) | 2022.11.10 |
[백준-2750번/Java] 수 정렬하기 (0) | 2022.11.10 |
[백준-2941번/Java] 크로아티아 알파벳 (0) | 2022.11.10 |
Comments