๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm

[๋ฐฑ์ค€] 2783๋ฒˆ: ์‚ผ๊ฐ ๊น€๋ฐฅ(๊ตฌํ˜„)

by ์ฃผ๋ฐœ2 2020. 5. 16.
๋ฐ˜์‘ํ˜•

https://www.acmicpc.net/problem/2783

 

2783๋ฒˆ: ์‚ผ๊ฐ ๊น€๋ฐฅ

๋ฌธ์ œ ์œ ๋ช… ํŽธ์˜์  ์ฒด์ธ์  ์„ธ๋ธ25๋Š” ์‚ผ๊ฐ ๊น€๋ฐฅ์„ ์ „๊ตญ์—์„œ ๊ฐ€์žฅ ์‹ธ๊ฒŒ ํŒ๋งคํ•˜๊ณ  ์žˆ๋‹ค.  ์ด ํšŒ์‚ฌ์˜ ์ง์›๋“ค์€ ์‚ผ๊ฐ ๊น€๋ฐฅ์˜ ๊ฐ€๊ฒฉ์„ ์ „๊ตญ ์ตœ์ €๊ฐ€๋ฅผ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ๋งค์ผ ๊ทผ์ฒ˜์˜ ํŽธ์˜์ ์„ ๋ฐฉ๋ฌธํ•œ๋‹ค. ๊ทธ๏ฟฝ๏ฟฝ

www.acmicpc.net

์ฝ”๋“œ

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int X = scan.nextInt();	// X์›
		int Y = scan.nextInt();	// Y๊ทธ๋žจ
		int N = scan.nextInt();	// ํŽธ์˜์  ๊ฐฏ์ˆ˜
		double minPrice = (double)X/Y * 1000;	// 1000๊ทธ๋žจ ๊ฐ€๊ฒฉ
		
		for(int i=0; i<N; i++) {
			int X1 = scan.nextInt();	// ๊ฐ€๊ฒฉ
			int Y1 = scan.nextInt();	// ๊ทธ๋žจ
			double price = (double)X1/Y1 * 1000;
			minPrice = Math.min(minPrice, price);
		}
		
		System.out.println(minPrice);
		scan.close();
	}

}

ํ’€์ด

๋ฌธ์ œ์—์„œ ์ •๋‹ต๊ณผ์˜ ์˜ค์ฐจ๋Š” 0.01๊นŒ์ง€ ํ—ˆ์šฉ๋œ๋‹ค๊ณ  ํ•ด์„œ ์†Œ์ˆ˜์  ๋‘˜์งธ์ž๋ฆฌ๊นŒ์ง€ ๋ฐ˜์˜ฌ๋ฆผํ•˜๋Š”๊ฑด ์ค„ ์•Œ์•˜๋‹ค.

ํ•˜์ง€๋งŒ ๊ทธ๋ƒฅ ๊ฐ„๋‹จํ•˜๊ฒŒ doouble๋กœ ๊ณ„์‚ฐํ•˜๋ฉด ๋.

๊ฐ ์ž…๋ ฅ๋งˆ๋‹ค 1000๊ทธ๋žจ์˜ ๊ฐ€๊ฒฉ์„ ๊ณ„์‚ฐํ•˜๊ณ , 1000๊ทธ๋žจ๋‹น ๊ฐ€๊ฒฉ์ค‘ ๊ฐ€์žฅ ์ €๋ ดํ•œ ๊ฐ€๊ฒฉ์„ ์ €์žฅํ•˜๊ณ  ์ถœ๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

1000๊ทธ๋žจ ๊ฐ€๊ฒฉ์„ ๊ตฌํ• ๋•Œ, intํ˜•์—์„œ double๋กœ ํ˜•๋ณ€ํ™˜์„ ํ•ด์ฃผ์–ด์•ผํ•œ๋‹ค.

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€