Algorithm
[백준-2869번/Java] 달팽이는 올라가고 싶다.
1984
2022. 11. 10. 23:23
* 감으로 품(왜 맞는지 생각해봐야 함)
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