zoukankan      html  css  js  c++  java
  • HDU1070Milk

     Milk
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
     

    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

    Hint

    In the first case, milk Yili can be drunk for 2 days, it costs 10 Yuan. Milk Mengniu can be drunk for 5 days, it costs 20 Yuan. So Mengniu is the cheapest.In the second case, milk Guangming should be ignored. Milk Yanpai can be drunk for 5 days, but it costs 40 Yuan. So Mengniu is the cheapest.
    题意:这个人每天喝200ml,一次牛奶最多喝5天,求性价比最高的牛奶
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 struct Node {
     4     string s;
     5     int mol;
     6     int ml;
     7     double rate;
     8 } aa[101];
     9 int main() {
    10     int t;
    11     cin>>t;
    12     while(t--) {
    13         int n;
    14         cin>>n;
    15         for(int i=0; i<n; i++) {
    16             cin>>aa[i].s>>aa[i].mol>>aa[i].ml;
    17             if(aa[i].ml>=1200)
    18                 aa[i].rate=aa[i].mol/5;
    19             else if(aa[i].ml>=200) {
    20                 int x=aa[i].ml/200;
    21                 aa[i].rate=aa[i].mol/(double)(x*1.0);
    22             } else
    23                 aa[i].rate=-1;
    24         }
    25         double minn=0x1f1f1f1f;
    26         int k;
    27         for(int j=0; j<n; j++) {
    28             if(aa[j].rate!=-1) {
    29                 if(aa[j].rate!=-1) {
    30                     if(aa[j].rate<minn) {
    31                         minn=aa[j].rate;
    32                         k=j;
    33                     }
    34                 }
    35             }
    36         }
    37         cout<<aa[k].s<<endl;
    38     }
    39     return 0;
    40 }
     
  • 相关阅读:
    总结
    PHP的重载-使用魔术方法实现
    用PHP实现一些常见的排序算法
    MySQL分组聚合group_concat + substr_index
    各种链接地址
    在Linux服务器上使用rz命令上传文件时时老报:Segmentation Fault,上传失败
    新安装的windows 10无法更新报0x80240fff错误的解决方案
    通过SSH key获取GitHub上项目,导入到IDEA中
    解压.zip,.tar.gz文件到指定目录,重命名文件
    byte字节数组的压缩
  • 原文地址:https://www.cnblogs.com/zhien-aa/p/5694481.html
Copyright © 2011-2022 走看看