【HDOJ】1070 milk
题目注意性价比需要使用double类型。
1 #include <stdio.h> 2 #include <string.h> 3 4 #define NAMELEN 105 5 #define INS 9999999 6 7 typedef struct { 8 char name[NAMELEN]; 9 int price, v; 10 } milkInfo_st; 11 12 int main() { 13 int case_n, n; 14 milkInfo_st tmp, best; 15 int i; 16 double k, j; 17 18 scanf("%d", &case_n); 19 20 while (case_n--) { 21 scanf("%d%*c", &n); 22 j = INS; 23 while (n--) { 24 scanf("%s %d %d%*c", tmp.name, &tmp.price, &tmp.v); 25 if (tmp.v < 200) 26 continue; 27 i = tmp.v / 200; 28 if (i>5) i = 5; 29 k = tmp.price*1.0f / i; 30 if (k<j) { 31 j = k; 32 strcpy(best.name, tmp.name); 33 best.price = tmp.price; 34 best.v = tmp.v; 35 } else if (k==j && tmp.v > best.v) { 36 strcpy(best.name, tmp.name); 37 best.price = tmp.price; 38 best.v = tmp.v; 39 } 40 } 41 printf("%s\n", best.name); 42 } 43 44 return 0; 45 }