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 }
     
  • 相关阅读:
    postgresql小纪
    Java的大内存分页支持
    GCViewer / MAT
    js给数组去重写法
    解决mybatis foreach 错误: Parameter '__frch_item_0' not found
    JSON字符串和JS对象之间的转换
    使用IntelliJ IDEA搭建多maven模块JAVA项目
    jstl中的sql:query标签获取的结果如何格式化输出
    Label控件如何根据字符串自定义大小
    winform/窗体鼠标事件编程中的几个问题
  • 原文地址:https://www.cnblogs.com/zhien-aa/p/5694481.html
Copyright © 2011-2022 走看看