[HDU] [1070] Milk

Problem Description

Loading...

Problem Analysis

Convert the value into value per day based on the number of usable days.
Note that it can be kept for at most 5 days.
So even when there is a lot of capacity, it can only be counted as 5 days.

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node {
	char s[120];
	double p;
	int d;
} a[120];
bool cmp(node A,node B) {
	if(A.p==B.p)
		return A.d>B.d;
	else
		return A.p<B.p;
}
int main() {
	int T;
	scanf("%d",&T);
	while(T--) {
		int n;
		scanf("%d",&n);
		for(int i=0; i<n; i++) {
			scanf("%s %lf %d",&a[i].s,&a[i].p,&a[i].d);
			if(a[i].d<200)
				i--,n--;
			else {
				if(a[i].d/200<=5)
					a[i].p/=a[i].d/200;
				else
					a[i].p/=5;
			}

		}
		sort(a,a+n,cmp);
		printf("%s\n",a[0].s);
	}
	return 0;
}

Problem link: HDU 1070 Milk

Loading...