2017湖南多校第四场-C(1037): Pizza Pricing

Problem C: Pizza Pricing
Source file: pizza.{c, cpp, java}
Input file: pizza.in
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
Diameter Price
5 inch 210inch 6
12 inch 8Onecouldactuallycomputethecostspersquareinch,whichwouldbeapproximately10.2¢,7.6¢,and7.1¢respectively,sothe12inchpizzaisthebestvalue.However,ifthe10inchhadbeensoldfor 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 6 N 6 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 6 D 6 36 and 1 6 P 6 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.
Example input: Example output:
3
5 2
10 6
12 8
3
5 2
10 5
12 8
4
1 1
24 33
13 11
6 11
0
Menu 1: 12
Menu 2: 10
Menu 3: 24

题目大意:给出pizza的直径和价格,单位面积的价格最小的pizza的直径
解题思路:直接计算,比较大小

#include <iostream>
#include <string>
#include <cmath>
#include <cstring>
using namespace std;
#define PI (acos(-1.0))

int main()
{
    int n;
    double d,p;
    double best;
    int bestd;
    int cas=1;
    while(cin>>n)
    {
        best=10000000000;
        bestd=0;
        if(n==0) break;
        while(n--)
        {
            cin>>d>>p;
            double tmp=(p*100)/(PI*(d/2)*(d/2));
            //cout<<tmp<<endl;
            if(best>tmp)
            {
                best=tmp;
                bestd=d;
            }
            //cout<<best<<endl;
        }
        cout<<"Menu "<<cas++<<": "<<bestd<<endl;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值