zoukankan      html  css  js  c++  java
  • HDU 1070 Milk

    Milk

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12363    Accepted Submission(s): 3009

    Problem Description
    Ignatius drinks milk everyday, now he is in the supermarket and he wants to choose a bottle of milk. There are many kinds of milk in the supermarket, so Ignatius wants to know which kind of milk is the cheapest.
    Here are some rules: 1. Ignatius will never drink the milk which is produced 6 days ago or earlier. That means if the milk is produced 2005-1-1, Ignatius will never drink this bottle after 2005-1-6(inclusive). 2. Ignatius drinks 200mL milk everyday. 3. If the milk left in the bottle is less than 200mL, Ignatius will throw it away. 4. All the milk in the supermarket is just produced today.
    Note that Ignatius only wants to buy one bottle of milk, so if the volumn of a bottle is smaller than 200mL, you should ignore it. Given some information of milk, your task is to tell Ignatius which milk is the cheapest.
     
    Input
    The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case starts with a single integer N(1<=N<=100) which is the number of kinds of milk. Then N lines follow, each line contains a string S(the length will at most 100 characters) which indicate the brand of milk, then two integers for the brand: P(Yuan) which is the price of a bottle, V(mL) which is the volume of a bottle.
     
    Output
    For each test case, you should output the brand of the milk which is the cheapest. If there are more than one cheapest brand, you should output the one which has the largest volume.
     
    Sample Input
    2 2 Yili 10 500 Mengniu 20 1000 4 Yili 10 500 Mengniu 20 1000 Guangming 1 199 Yanpai 40 10000
     
    Sample Output
    Mengniu Mengniu
     
     
    解题报告:简单的模拟题,要注意的就是6天后不能喝的意思是只能喝5天,被坑了!一直以为是精度问题。。。
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<algorithm>
     5 #include<cmath>
     6 using namespace std;
     7 struct node
     8 {
     9     char name[105];
    10     double p,v;
    11 }milk[105];
    12 double get_p(double p,double v)
    13 {
    14     if(v < 200)
    15     return 0x7fffffff;
    16     int d = (int)v / 200;
    17     d = min(d,5);
    18     return p / (double)d;
    19 }
    20 
    21 int main()
    22 {
    23     int T;
    24     scanf("%d",&T);
    25     while(T--)
    26     {
    27         int n;
    28         scanf("%d",&n);
    29         for(int i = 0;i < n;++i)
    30         scanf("%s %lf %lf",milk[i].name,&milk[i].p,&milk[i].v);
    31         int f = 0;
    32         double ch = 0x7fffffff;
    33         for(int i = 0;i < n;++i)
    34         {
    35             double pr = get_p(milk[i].p,milk[i].v);
    36             if(abs(pr - ch) < 0.000001)
    37             {
    38                 if(milk[i].v > milk[f].v)
    39                 f = i;
    40 //                printf("%s   %lf
    ",milk[i].name,pr);
    41             }
    42             else if(pr < ch)
    43             {
    44                 f = i;
    45                 ch = pr;
    46 //                printf("%s   %lf
    ",milk[i].name,pr);
    47             }
    48         }
    49         printf("%s
    ",milk[f].name);
    50     }
    51     return 0;
    52 }
    View Code
  • 相关阅读:
    [文档].Altera 可选择的Nios II的Boot方法
    [原创].关于使用QII 10.0编译器无法编辑和查看中文的问题一个变通解决方案
    判断某程序是64位还是32位
    在调用RestoreSPSite时指定ContentDatabase
    CAML join
    ADODB.Connection Invalid connection error
    Sharepoint 如何修改Web.Config文件
    ActivateOnDefault & AutoActivateInCentralAdmin feature 属性
    Sharepoint 2010 解决DFWP Unable to display this Web Part 的问题
    Powershell点滴
  • 原文地址:https://www.cnblogs.com/xiaxiaosheng/p/3597214.html
Copyright © 2011-2022 走看看