zoukankan      html  css  js  c++  java
  • HDU1070 Milk 细节决定成败

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1070

    注意:1.喝到第五天,第六天就不喝了  2.相同花费的,优先考虑容量大的  3.注意强制类型转换 4.精度一定要注意

    附上题解:

      
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    const int maxn = 100 + 10;
    typedef struct Milk{
        int yuan;
        int value;
        char name[maxn];
        double weight; //保存代价
    }Milk;
    Milk a[maxn]; //结构体数组存放
    
    void solve(int n)
    {
        int p, j;
        double min = 999999; //精度要注意
        for(int i = 0; i < n; i++){
            if(a[i].value < 200) continue;
            if(a[i].value >= 1000) p = 5;
            else p = a[i].value/200;
            a[i].weight = double(a[i].yuan/p); //注意类型转换
            if(a[i].weight < min){
                min = a[i].weight;
                j = i;
            }
            else if(a[i].weight == min){
                if(a[i].value > a[j].value){
                    j = i;
                }
            }
        }
        printf("%s
    ", a[j].name);
    }
    
    int main()
    {
        int t, n;
        while(~scanf("%d", &t)){
            while(t--){
                memset(a, 0, sizeof(a));
                scanf("%d", &n);
                for(int i = 0; i < n; i++)
                    scanf("%s%d%d", a[i].name, &a[i].yuan, &a[i].value);
                solve(n);
            }
        }
        return 0;
    } 
  • 相关阅读:
    Gentle.Net学习笔记一:配置文件设置
    啥时候咱能用上NExcelApi?
    ibus no input window
    QT && GDAL
    安装 purcell 的emacs.d 配置文件
    进程
    C++的cout高阶格式化操作
    C++ 虚函数表解析
    [转]C程序内存区域分配(5个段作用)
    如何写Makefile文件
  • 原文地址:https://www.cnblogs.com/ACFLOOD/p/4162803.html
Copyright © 2011-2022 走看看