์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ/BOJ_Java

[BOJ/Step8] 1712 : ์†์ต๋ถ„๊ธฐ์  (JAVA)

NaNaRin๐Ÿ™ƒ 2021. 1. 16. 20:11

www.acmicpc.net/problem/1712

 

1712๋ฒˆ: ์†์ต๋ถ„๊ธฐ์ 

์›”๋“œ์ „์ž๋Š” ๋…ธํŠธ๋ถ์„ ์ œ์กฐํ•˜๊ณ  ํŒ๋งคํ•˜๋Š” ํšŒ์‚ฌ์ด๋‹ค. ๋…ธํŠธ๋ถ ํŒ๋งค ๋Œ€์ˆ˜์— ์ƒ๊ด€์—†์ด ๋งค๋…„ ์ž„๋Œ€๋ฃŒ, ์žฌ์‚ฐ์„ธ, ๋ณดํ—˜๋ฃŒ, ๊ธ‰์—ฌ ๋“ฑ A๋งŒ์›์˜ ๊ณ ์ • ๋น„์šฉ์ด ๋“ค๋ฉฐ, ํ•œ ๋Œ€์˜ ๋…ธํŠธ๋ถ์„ ์ƒ์‚ฐํ•˜๋Š” ๋ฐ์—๋Š” ์žฌ๋ฃŒ๋น„์™€

www.acmicpc.net


๋ฌธ์ œ

์›”๋“œ์ „์ž๋Š” ๋…ธํŠธ๋ถ์„ ์ œ์กฐํ•˜๊ณ  ํŒ๋งคํ•˜๋Š” ํšŒ์‚ฌ์ด๋‹ค. ๋…ธํŠธ๋ถ ํŒ๋งค ๋Œ€์ˆ˜์— ์ƒ๊ด€์—†์ด ๋งค๋…„ ์ž„๋Œ€๋ฃŒ, ์žฌ์‚ฐ์„ธ, ๋ณดํ—˜๋ฃŒ, ๊ธ‰์—ฌ ๋“ฑ A๋งŒ์›์˜ ๊ณ ์ • ๋น„์šฉ์ด ๋“ค๋ฉฐ, ํ•œ ๋Œ€์˜ ๋…ธํŠธ๋ถ์„ ์ƒ์‚ฐํ•˜๋Š” ๋ฐ์—๋Š” ์žฌ๋ฃŒ๋น„์™€ ์ธ๊ฑด๋น„ ๋“ฑ ์ด B๋งŒ์›์˜ ๊ฐ€๋ณ€ ๋น„์šฉ์ด ๋“ ๋‹ค๊ณ  ํ•œ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด A=1,000, B=70์ด๋ผ๊ณ  ํ•˜์ž. ์ด ๊ฒฝ์šฐ ๋…ธํŠธ๋ถ์„ ํ•œ ๋Œ€ ์ƒ์‚ฐํ•˜๋Š” ๋ฐ๋Š” ์ด 1,070๋งŒ์›์ด ๋“ค๋ฉฐ, ์—ด ๋Œ€ ์ƒ์‚ฐํ•˜๋Š” ๋ฐ๋Š” ์ด 1,700๋งŒ์›์ด ๋“ ๋‹ค.

๋…ธํŠธ๋ถ ๊ฐ€๊ฒฉ์ด C๋งŒ์›์œผ๋กœ ์ฑ…์ •๋˜์—ˆ๋‹ค๊ณ  ํ•œ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ ์ƒ์‚ฐ ๋Œ€์ˆ˜๋ฅผ ๋Š˜๋ ค ๊ฐ€๋‹ค ๋ณด๋ฉด ์–ด๋Š ์ˆœ๊ฐ„ ์ด ์ˆ˜์ž…(ํŒ๋งค๋น„์šฉ)์ด ์ด ๋น„์šฉ(=๊ณ ์ •๋น„์šฉ+๊ฐ€๋ณ€๋น„์šฉ)๋ณด๋‹ค ๋งŽ์•„์ง€๊ฒŒ ๋œ๋‹ค. ์ตœ์ดˆ๋กœ ์ด ์ˆ˜์ž…์ด ์ด ๋น„์šฉ๋ณด๋‹ค ๋งŽ์•„์ ธ ์ด์ต์ด ๋ฐœ์ƒํ•˜๋Š” ์ง€์ ์„ ์†์ต๋ถ„๊ธฐ์ (BREAK-EVEN POINT)์ด๋ผ๊ณ  ํ•œ๋‹ค.

A, B, C๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์†์ต๋ถ„๊ธฐ์ ์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— A, B, C๊ฐ€ ๋นˆ ์นธ์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. A, B, C๋Š” 21์–ต ์ดํ•˜์˜ ์ž์—ฐ์ˆ˜์ด๋‹ค.

 

์ถœ๋ ฅ

์ฒซ ๋ฒˆ์งธ ์ค„์— ์†์ต๋ถ„๊ธฐ์  ์ฆ‰ ์ตœ์ดˆ๋กœ ์ด์ต์ด ๋ฐœ์ƒํ•˜๋Š” ํŒ๋งค๋Ÿ‰์„ ์ถœ๋ ฅํ•œ๋‹ค. ์†์ต๋ถ„๊ธฐ์ ์ด ์กด์žฌํ•˜์ง€ ์•Š์œผ๋ฉด -1์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ 1

1000 70 170

 

์˜ˆ์ œ ์ถœ๋ ฅ 1

11

 

์˜ˆ์ œ ์ž…๋ ฅ 2

3 2 1

 

์˜ˆ์ œ ์ถœ๋ ฅ 2

-1


ํ’€์ด

1. ๋…ธํŠธ๋ถ์ด n๋Œ€ ํŒ๋งค๋˜์—ˆ๋‹ค๊ณ  ํ•  ๋•Œ ์†์ต๋ถ„๊ธฐ์ ์„ ๊ตฌํ•˜๋Š” ์‹์€ n > A / ( C - B )

2. ํ•ด๋‹น ์‹๋ณด๋‹ค ํฐ ์ž์—ฐ์ˆ˜๋ฅผ ๊ตฌํ•˜์—ฌ์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— intํ˜• d ์— (double)a / ( (double)c - (double)b ) + 1์„ ์ €์žฅ

   (doubleํ˜•์„ int๋กœ ์ €์žฅํ•˜๋ฉด ๋‚˜๋จธ์ง€๋ฅผ ๋‹ค ๋ฒ„๋ฆฌ๊ณ  ์ •์ˆ˜ ๋ถ€๋ถ„๋งŒ ๋‚จ๊ธฐ ๋•Œ๋ฌธ์—) 

3. d๊ฐ€ 1๋ณด๋‹ค ์ž‘๋‹ค๋ฉด ์†์ต๋ถ„๊ธฐ์ ์ด ์กด์žฌํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— -1์„ ์ถœ๋ ฅ, ์•„๋‹ˆ๋ฉด d๋ฅผ ์ถœ๋ ฅ

 

import java.io.IOException;
import java.util.Scanner;
import java.util.StringTokenizer;

public class B1712 {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		StringTokenizer st = new StringTokenizer(sc.nextLine());
		
		String a = st.nextToken();
		String b = st.nextToken();
		String c = st.nextToken();
		
		int d = (int) (Double.parseDouble(a) / ( Double.parseDouble(c) - Double.parseDouble(b) )) + 1;

		if(d < 1) {
			System.out.println("-1");
		} else {
			System.out.println(d);
		}
	}
}