zoukankan      html  css  js  c++  java
  • SDNU 1155.Pizza Pricing

    Description

    Pizza has always been a staple on college campuses. After the downturn in the economy, it is more important than ever to get the best deal, namely the lowest cost per square inch. Consider, for example, the following menu for a store selling circular pizzas of varying diameter and price:

    Menu
    DiameterPrice
    5 inch $2
    10 inch $6
    12 inch $8

    One could actually compute the costs per square inch, which would be approximately 10.2¢, 7.6¢, and 7.1¢ respectively, so the 12-inch pizza is the best value. However, if the 10-inch had been sold for $5, it would have been the best value, at approximately 6.4¢ per square inch.

    Your task is to analyze a menu and to report the diameter of the pizza that is the best value. Note that no two pizzas on a menu will have the same diameter or the same inherent cost per square inch.

    Input

    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), with 1 ≤ D ≤ 36 and 1 ≤ P ≤ 100. The end of the input will be designated with a line containing the number 0.

    Output

    For each menu, print a line identifying the menu number and the diameter D of the pizza with the best value, using the format shown below.

    Sample Input

    3
    5 2
    10 6
    12 8
    3
    5 2
    10 5
    12 8
    4
    1 1
    24 33
    13 11
    6 11
    0

    Sample Output

    Menu 1: 12
    Menu 2: 10
    Menu 3: 24

    Source

    #include <cstdio>
    #include <iostream>
    #include <cmath>
    #include <string>
    #include <cstring>
    #include <algorithm>
    #include <queue>
    
    using namespace std;
    
    #define ll long long
    const double pi = acos(-1.0);
    
    int n, d[18], p[18], miao = 0, sum;
    double s[18];
    int main()
    {
        while(scanf("%d", &n) && n)
        {
            sum = 0;
            for(int i = 0; i<n; i++)
            {
                scanf("%d%d", &d[i], &p[i]);
                s[i] = (double)p[i]/(pow(d[i], 2)*pi);
    //            printf("%lf
    ", s[i]);
            }
    //        printf("
    ");
            for(int i = 1; i<n; i++)
            {
                if(s[sum]>s[i])sum = i;
            }
            miao++;
            printf("Menu %d: %d
    ", miao, d[sum]);
        }
        return 0;
    }
  • 相关阅读:
    正则表达式(常用正则总结)
    What is maven?
    二维数组的遍历使用foreach
    Installing Git
    Hive修改表名,列名,列注释,表注释,增加列,调整列顺序,属性名等操作
    有趣的开源项目集结完毕,HelloGitHub 月刊第 63 期发布啦!
    - zxvf
    tensorflow入门
    Postman v8.7.0
    springboot等javaweb项目将jar包安装(打包)到本地Maven仓库
  • 原文地址:https://www.cnblogs.com/RootVount/p/10422096.html
Copyright © 2011-2022 走看看