hdu1070Milk

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

水。

代码:
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

struct Node{
    char s[105];
    int price;
    int v;
    double perPrice;
}a[105];

bool cmp(Node x,Node y)

{
    if(x.perPrice != y.perPrice)
        return x.perPrice < y.perPrice;
    else if(x.v != y.v)
        return x.v > y.v;
}

int main()

{
    int _;
    scanf("%d",&_);
    while(_--)
    {
        memset(a,0,sizeof(a));
        int n;
        scanf("%d",&n);
        for(int i = 0;i < n;++i)
        {
            scanf("%s%d%d",a[i].s,&a[i].price,&a[i].v);
            if(a[i].v / 200)
            {
                int t = a[i].v / 200;
                if(t > 5)
                    t = 5;
                a[i].perPrice = (double)a[i].price / t;
            }
        }
        sort(a,a + n,cmp);
        for(int i = 0;i < n;++i)
        {
            if(a[i].perPrice)
            {
                printf("%s\n",a[i].s);
                break;
            }
        }
    }
    return 0;
}

你可能感兴趣的:(ACM)