• MILK


    //这个题目理解上有些坑啊 而且我后来在变量的比较上也出了一些问题,不难但是要注意看清题目的意思 

    //应该用实际能饮用的天数去除价格,得到天数价格比。然后对其排序。

    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

    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.

    MILK
    
    /*这个题目需要注意的是:    *1、容量小于200的牌子需要忽略,不参与计算【容量小于200的不会买】     *2、买的牛奶只喝5天,5天之后有多的就要倒掉【但并不是超过1000容量的就不买! 】    *3、因为多的要倒掉,因此只能计算每天的花费【而不是每ml的花费!】     *4、剩余少于200ml需要倒掉,因此在计算5天内可以喝完的牛奶喝完需要喝的天数直接对200进行整除     */
    
    
    
    #include<stdio.h>
    
    #include<algorithm>
    
    using namespace std;
    
    
    
    struct milk
    
    {
    
    char name[1000];
    
    int volume,v;
    
    }stu[1000];
    
    
    
    bool cmp(milk a,milk b)
    
    {
    
    if(a.volume!=b.volume)
    
    return a.volume<b.volume;
    
    else
    
    return a.v>b.v;
    
    }
    
    
    
    int main()
    
    {
    
    int t,n,day,p,v;
    
    scanf("%d",&t);
    
    while(t--)
    
    {
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++)
    
    {
    
    scanf("%s %d %d",stu[i].name,&p,&stu[i].v);
    
    int day=stu[i].v/200;
    
    if(day>=5)
    
    {
    
    day=5;
    
    stu[i].volume=p/day;
    
    }
    
    else if(day<5&&day>0)
    
    {
    
    stu[i].volume=1.0*p/day;
    
    }
    
    else
    
    stu[i].volume=100000;
    
    }
    
    sort(stu,stu+n,cmp);
    
    printf("%s
    ",stu[0].name);
    
    }
    
    return 0;
    
    }
    
    //应该用实际能饮用的天数去除价格,得到天数价格比。然后对其排序。
  • 相关阅读:
    JDK5.0新特性系列10.监控与管理虚拟机
    JDK5.0新特性系列7.使用ProcessBuilder执行本地命令
    JDK5.0新特性系列4.静态导入
    JDK5.0新特性系列8.泛型编程
    JDK5.0新特性系列11.2线程 任务执行架构
    JDK5.0新特性系列6.格式化输出
    Request的编码问题,客户端为繁体系统时为乱码解决了。
    智能手机之新手篇[转]
    一篇颇有感触的文章
    修复Oracle9i中DBA的密码
  • 原文地址:https://www.cnblogs.com/awsent/p/4266882.html
Copyright © 2020-2023  润新知