ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ๋ฌธ์ œ

 

4573๋ฒˆ: Pizza Pricing

The input contains a series of one or more menus. Each menu starts with the number of options N, 1 ≤ N ≤ 10, followed by N lines, each containing two integers respectively designating a pizza's diameter D (in inches) and price P (in dollars), wit

www.acmicpc.net


โœ๐Ÿป ํ’€์ด

๐ŸŽจ Go

// https://www.acmicpc.net/problem/4573
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var menu int
	for {
		menu++
		var n int
		fmt.Fscanln(reader, &n)
		if n == 0 {
			break
		}
		var selectedDiamater int
		var lowPricePerSquare = math.MaxFloat64
		for i := 0; i < n; i++ {
			var diameter, price int
			fmt.Fscanln(reader, &diameter, &price)
			var radius = float64(diameter) / 2.0
			var pricePerSquare = float64(price) / (radius * radius * math.Phi)
			if pricePerSquare < lowPricePerSquare {
				lowPricePerSquare = pricePerSquare
				selectedDiamater = diameter
			}
		}
		fmt.Fprintf(writer, "Menu %d: %d\n", menu, selectedDiamater)
	}
}

๐ŸŽจ Python3

# https://www.acmicpc.net/problem/4573
import sys
import math

if __name__ == "__main__":
    menu = 0
    while True:
        menu += 1
        n = int(sys.stdin.readline())
        if n == 0:
            break
        selected_diamter = 0
        low_price_per_square = 10000
        for i in range(n):
            diameter, price = list(map(int, sys.stdin.readline().split()))
            radius = diameter/2.0
            price_per_square = price / (radius*radius*math.pi)
            if price_per_square < low_price_per_square:
                low_price_per_square = price_per_square
                selected_diamter = diameter
        print("Menu {}: {}".format(menu, selected_diamter))
728x90
๋Œ“๊ธ€