-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_2869.java
More file actions
67 lines (60 loc) ยท 2.04 KB
/
_2869.java
File metadata and controls
67 lines (60 loc) ยท 2.04 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package backjoon;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
// https://www.acmicpc.net/problem/2869
// ๋ฌํฝ์ด๋ ์ฌ๋ผ๊ฐ๊ณ ์ถ๋ค.
public class _2869 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// sol1 ์๊ฐ์ด๊ณผ๋ก ์คํจ
/*
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
// String[] input = br.readLine().split(" "); // ์๊ฐ์ด๊ณผ -> StringTokenizer๋ก ๋ณ๊ฒฝ
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int A = Integer.parseInt(st.nextToken()); // ๋ฎ์ ์ฌ๋ผ๊ฐ๋ ๋์ด
int B = Integer.parseInt(st.nextToken()); // ๋ฐค์ ๋ฏธ๋๋ฌ์ง๋ ๋์ด
int V = Integer.parseInt(st.nextToken()); // ์ ์ ๋์ด
int oneDay = A - B; // ํ๋ฃจ๋์ ์ฌ๋ผ๊ฐ ์ ์๋ ๋์ด
int day = 0;
int sum = 0; // ๋์ ๋์ด
while (sum < V) {
sum += oneDay;
if (sum == V) {
break;
}
day++;
}
// System.out.println(day); // ์๊ฐ์ด๊ณผ -> BufferedWriter๋ก ๋ณ๊ฒฝ
bw.write(String.valueOf(day));
bw.flush();
bw.close();
*/
// sol2 ์๊ฐ์ด๊ณผ๋ฅผ ํด๊ฒฐํ๊ธฐ์ํด ๋ฐ๋ณต๋ฌธ ์์ด ํด๊ฒฐ
// memory 11500 runtime 76
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int A = Integer.parseInt(st.nextToken()); // ๋ฎ์ ์ฌ๋ผ๊ฐ๋ ๋์ด
int B = Integer.parseInt(st.nextToken()); // ๋ฐค์ ๋ฏธ๋๋ฌ์ง๋ ๋์ด
int V = Integer.parseInt(st.nextToken()); // ์ ์ ๋์ด
// ์ ์์ ๋๋ฌํ๋ ค๋ฉด (V / (A-B))์ ๋๋จธ์ง๊ฐ 0์ด๋ฉด ๋๋ค. ํ์ง๋ง ์ด๊ณผํด์ ๋๋ฌํ ๊ฒฝ์ฐ์๋ ๋ฏธ๋๋ฌ์ง์ง์์ผ๋ฏ๋ก V-B๋ฅผ ๋นผ์ค๋ค.
int day = (V - B) / (A - B);
//๋๋จธ์ง๊ฐ ์๋ค๋ฉด ์์ง ๋๋ฌํ์ง ๋ชปํ ๊ฒ์ด๋ฏ๋ก ํ๋ฃจ๊ฐ ์ถ๊ฐ๋๋ค.
if((V - B) % (A - B) != 0){
day++;
}
System.out.println(day);
}
}
/*
input
2 1 5
5 1 6
100 99 1000000000
output
4
2
999 999 901
*/