• HDU 1070 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
    
    
    
    HintIn 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.
    

    分析:

    简单的结构体排序,要找到最简单的牛奶,肯定就是单价最少的。

    代码:

    #include<iostream>
    #include<stdio.h>
    #include<cstdlib>
    #include<string>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    struct Niunai
    {
        char str[103];
        double a;///价钱
        double b;///体积
        double c;///单价
    } aa[104];
    bool camp(Niunai x,Niunai y)
    {
        if(x.c!=y.c)///单价按照从小到大排序
            return (x.c<y.c);
        else
            return (x.b>y.b);///单价相同,按照体积从大到小排序
    }
    int main()
    {
        int n;
        scanf("%d",&n);
        while(n--)
        {
            memset(aa,0,sizeof(aa));///每次进行完,数组要刷新,
            int m;
            double n1;
            scanf("%d",&m);
            for(int i=0; i<m; i++)
            {
                scanf("%s%lf%lf",aa[i].str,&aa[i].a,&aa[i].b);
                if(aa[i].b<200)
                    aa[i].c=0x3f3f3f;
                else
                {
                    n1=(int)(aa[i].b/200);
                    if(n1>=5)
                        n1=5;
                    aa[i].c=(double)(aa[i].a/n1);///得到每天的价钱
                }
            }
            sort(aa,aa+m,camp);
            printf("%s
    ",aa[0].str);
        }
        return 0;
    }
  • 相关阅读:
    Vue响应式原理
    vue 与 react
    vuex
    受控组件( controlled component )与不受控制的组件( uncontrolled component )区别
    redux学习语录
    Flux
    MVC和MVVM 架构模式/设计思想
    immutable
    JS中一些兼容性问题
    @芥末的糖 ---------- node连接数据库两种方式mysql和moogoDB
  • 原文地址:https://www.cnblogs.com/cmmdc/p/6764205.html
Copyright © 2020-2023  润新知