-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_1712.java
More file actions
63 lines (56 loc) ยท 2.08 KB
/
_1712.java
File metadata and controls
63 lines (56 loc) ยท 2.08 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
package backjoon;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
// https://www.acmicpc.net/problem/1712
// ์์ต๋ถ๊ธฐ์
public class _1712 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// ์๋ชป๋ ์ ๊ทผ๋ฐฉ์์ผ๋ก ์ฃ์ง์ผ์ด์ค์ ๊ฑธ๋ ค ์คํจ
/*
String[] money = br.readLine().split(" ");
int fixed = Integer.parseInt(money[0]);
int variable = Integer.parseInt(money[1]);
int calvariable = variable;
int price = Integer.parseInt(money[2]);
int calPrice = price;
int sales = 1;
while(calPrice <= fixed+calvariable){
sales++;
calPrice = price * sales;
calvariable = variable * sales;
if(calvariable < 0 ){
sales = -1;
break;
}
}
System.out.println(sales);
*/
// memory 11496 runtime 76
// ํ ์ค์ space๋ก ๊ตฌ๋ถ๋์ด ์์๋ StringTokenizer๋ฅผ ์ฌ์ฉํ๋ค.
StringTokenizer st = new StringTokenizer(br.readLine());
// ์ด ์์
๊ณผ ์ด ์ง์ถ์ด ๊ฐ์ ๋์ ์์ผ๋ก ๋ํ๋ด๋ฉด (price * sales) = fixed+(variable * sales)
// ํ๋งค๋๋ง ์ข๋ณ์ ๋จ๋๋ก ์์ ์ ๋ฆฌํ๋ฉด sales = fixed / (price-variable)
// ์์ต๋ถ๊ธฐ์ ์ fixed / (price-variable) + 1 ์ด ๋์ด์ผํ๋ค.
// ์ฌ๊ธฐ์ ๋ชจ๋ ์๋ ์์ฐ์์ด๊ธฐ์ [ {fixed / (price-variable)} + 1 ] > 0 ์ด์ด์ผํ๋ค.
// ๋ฐ๋ผ์ ๋ถ๋ชจ์ธ (price-variable) ๊ฐ 0๋ณด๋ค ์ปค์ผ ์ด์ต์ด ์๊ธฐ๊ณ 0๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ผ๋ฉด ์ด์ต์ด ์๊ธฐ์ง ์๋๋ค.
// ์ด๊ฑธ ์์ผ๋ก ์ ๋ฆฌํ๋ฉด price > variable ์ผ๋ ์ด์ต์ด ์๊ธฐ๊ณ price <= variable์ผ๋๋ ์ด์ต์ด ๋ฐ์ํ์ง ์๋๋ค.
int fixed = Integer.parseInt(st.nextToken());
int variable = Integer.parseInt(st.nextToken());
int price = Integer.parseInt(st.nextToken());
if (price <= variable) {
System.out.println("-1");
}
else {
System.out.println((fixed/(price-variable))+1);
}
}
}
/*
input
1000 70 170
output
11
*/