HDU 1070 struct
I can only say that I am crazy to be tortured by this question, and I have no confidence at all. Wrong answer is close to two hours, and I am heartbroken by WA. However, the AC is still used. It is still careless. This is a struct question (it can be done without a struct ). The question below. MilkTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 14398 Accepted Submission (s): 3551
Problem DescriptionIgnatius drinks milk everyday, now he is in the supermarket and he wants to choose a bottle of milk. there are running kinds of milk in the supermarket, so Ignatius wants to know which kind of milk is the cheapest.
Here are some rules:
1. Ignatius will never drink the milk which is produced 6 days ago or earlier. That means if the milk is produced 2005-1-1, Ignatius will never drink this bottle after 2005-1-6 (random SIVE ).
2. Ignatius drinks 200 mL milk everyday.
3. If the milk left in the bottle is less than 200 mL, Ignatius will throw it away.
4. All the milk in the supermarket is just produced today.
Note that Ignatius only wants to buy one bottle of milk, so if the volumn of a bottle is smaller than 200, you shoshould ignore it.
Given some information of milk, your task is to tell Ignatius which milk is the cheapest.
InputThe input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case starts with a single integer N (1 <= N <= 100) which is the number of kinds of milk. then N lines follow, each line contains a string S (the length will at most 100 characters) which indicate the brand of milk, then two integers for the brand: P (Yuan) which is the price of a bottle, V (mL) which is the volume of a bottle.
OutputFor each test case, you shoshould output the brand of the milk which is the cheapest. If there are more than one cheapest brand, you shoshould output the one which has the largest volume.
Sample Input
22Yili 10 500Mengniu 20 10004Yili 10 500Mengniu 20 1000Guangming 1 199Yanpai 40 10000
Sample Output
MengniuMengniuHintIn the first case, milk Yili can be drunk for 2 days, it costs 10 Yuan. Milk Mengniu can be drunk for 5 days, it costs 20 Yuan. So Mengniu is the cheapest.In the second case,milk Guangming should be ignored. Milk Yanpai can be drunk for 5 days, but it costs 40 Yuan. So Mengniu is the cheapest.
AuthorIgnatius. L The question is to give you the brand of milk, the cost, the volume. Let you determine which one to buy is the most cost-effective. Note: If the volume is less than two hundred, you do not need to drink. The amount of milk consumed per day is two hundred, and the maximum amount of milk consumed is five thousand. The code below. With detailed parsing.
# Include
# Include
Struct node // The information in the struct {char name [105]; // This is the name of the milk brand int v; // The volume of the milk int money; // spent money} f [105]; // used to store the preceding three variables void solve () {int n, m, I, j, p, max; // define the Variable p to indicate the number of days of drinking, n to represent several cases, m to represent the name, price, volume of m Brand milk while (scanf ("% d ", & n )! = EOF) {while (n --) {float sum; // Note: folat or double must be used here because (17/5 19/5 of values are the same, so floating point numbers must be used, to ensure that the price of each day is different) float min = 999999999; // make it equal to a large number to find the minimum number. Sum = 0; j = 0; max =-1; // let max be a small number to find the maximum number. Scanf ("% d", & m); // enter for (I = 1; I <= m; I ++) scanf ("% s % d ", f [I]. name, & f [I]. money, & f [I]. v); // enter the milk brand, the cost, volume, for (I = 1; I <= m; I ++) {if (f [I]. v <200) // if it is less than two hundred, continue (if it is less than two hundred, do not drink) continue; if (f [I]. v> 1000) // if it is greater than one thousand, P = 5, because you can drink for up to five days. P = 5; // elsep = f [I]. v/200; // otherwise, dividing by two hundred is the number of days of drinking sum = float (f [I]. money/p); // note that I'm WA many times here. (Cannot be written as float (f [I]. money)/p; the resulting number is an integer !!) If (sum
F [j]. v) // search for the big milk. {J = I; // assign the variable to j, which is the brand name with a large size.} printf ("% s \ n", f [j]. name); // output }}int main () {solve (); // solve the problem. Return 0 ;}