题意:这题是性价比问题,牛奶的平均价格=价格/天数,比较一下,当这个相等是,就要比较一下它们各自的容量了。考虑到这两点就可以了。
#include <cstdio>
#include <cstring>
#include <climits>
#include <algorithm>
using namespace std;
struct milk
{
char brand[101];
int price;
int volume;
};
int cmp(milk& a, milk& b)
{
int a_day = a.volume/200, b_day = b.volume/200;
a_day = a_day > 5 ? 5 : a_day;
b_day = b_day > 5 ? 5 : b_day;
if (a.price*b_day != b.price*a_day)
return double(a.price)/a_day < double(b.price)/b_day;
else
return a.volume > b.volume;
}
void main()
{
int T, N, n;
milk *p;
scanf("%d", &T);
while (T--)
{
scanf("%d", &N);
p = new milk[N];
n = N;
while (n--)
{
scanf("%s %d %d", &p[N-n-1].brand, &p[N-n-1].price, &p[N-n-1].volume);
if (p[N-n-1].volume < 200)
{
p[N-n-1].price = INT_MAX;
p[N-n-1].volume += 200;
}
}
sort(p, p+N, cmp);
printf("%s\n", p[0].brand);
delete[] p;
}
}