문제
There’s a pizza store which serves pizza in two sizes: either a pizza slice, with area A1 and price P1, or a circular pizza, with radius R1 and price P2.
You want to maximize the amount of pizza you get per dollar. Should you pick the pizza slice or the whole pizza?
입력
The first line contains two space-separated integers A1 and P1.
Similarly, the second line contains two space-separated integers R1 and P2.
It is guaranteed that all values are positive integers at most 103. We furthermore guarantee that the two will not be worth the same amount of pizza per dollar.
출력
If the better deal is the whole pizza, print ‘Whole pizza’ on a single line.
If it is a slice of pizza, print ‘Slice of pizza’ on a single line.
풀이
1. Whole pizza의 크기당 가격을 구한다.
2. Slice of pizza의 크기당 가격을 구한다.
3. 더 가성비가 좋은 피자를 출력한다.
코드
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double a=sc.nextDouble(), p=sc.nextDouble(), r=sc.nextDouble(), q=sc.nextDouble();
double x=a/p, y=Math.PI*r*r/q;
if(x<y)
System.out.println("Whole pizza");
else
System.out.println("Slice of pizza");
}
}
'Algorithm > Baekjoon' 카테고리의 다른 글
Baekjoon 10569 다면체 JAVA (0) | 2022.05.10 |
---|---|
Baekjoon 11721 열 개씩 끊어 출력하기 JAVA (0) | 2022.05.10 |
Baekjoon 20215 Cutting Corners JAVA (0) | 2022.05.05 |
Baekjoon 21335 Another Eruption JAVA (0) | 2022.05.05 |
Baekjoon 20352 Circus JAVA (0) | 2022.05.05 |
댓글