• [恢]hdu 1070


    2011-12-20 13:07:58

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=1070

    题意:故事的主角喝牛奶每天喝200ml,不到200ml的牛奶直接扔掉。一罐牛奶最多只喝5天,超过5天扔掉。给n个牌子的牛奶价格和体积,问哪个最便宜。。。

    mark:wa了n次,没看到题目的一句话:If there are more than one cheapest brand, you should output the one which has the largest volume.

    另外有两个牌子都大于1000ml的情况,我一开始直接把大于1000的volume赋为1000,就错了。

    代码:

    # include <stdio.h>
    # include <string.h>


    int min(int a, int b){return a<b?a:b;}


    int compare(int a, int b, int aa, int bb)
    {
    if (a*(min(bb,1000)/200) != aa*(min(b,1000)/200))
    return a*(min(bb,1000)/200) < aa*(min(b,1000)/200) ;
    return b > bb ;
    }


    int main ()
    {
    int i, T ;
    char brand[15], bbrand[15] ;
    int n, a, b, aa, bb ;
    scanf ("%d", &T) ;
    while (T--)
    {
    scanf ("%d", &n) ;
    scanf ("%s %d %d%*c", bbrand, &aa, &bb) ;
    for (i = 1 ; i < n ; i++)
    {
    scanf ("%s %d %d%*c", brand, &a, &b) ;
    if (b < 200) continue ;
    // if (b > 1000 ) b=1000 ;
    if (compare(a, b, aa, bb))
    {
    aa = a, bb = b ;
    strcpy (bbrand, brand) ;
    }
    }
    puts (bbrand) ;
    }
    return 0 ;
    }



  • 相关阅读:
    mysql max(),min()的优化
    统计网站某天的点击数
    小程序网络图片下载
    小程序封装
    小程序 封装调用
    小程序request封装
    git 使用
    MYSQL查询语句优化
    微信开发遇到的坑
    PHP支付宝支付开发流程
  • 原文地址:https://www.cnblogs.com/lzsz1212/p/2315285.html
Copyright © 2020-2023  润新知