Notice
Recent Posts
Recent Comments
Link
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags
more
Archives
Today
Total
관리 메뉴

main

[백준-2869번/Java] 달팽이는 올라가고 싶다. 본문

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
Comments