hdu 1070 Milk

虽然是水题,还是由于看题不细wa了几次。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <string>
 4 #include <vector>
 5 #include <algorithm>
 6 using namespace std;
 7 const int everyday_v = 200;
 8 const int drinkday = 5;
 9 struct Milk
10 {
11     string brand;
12     int price, volume, days;
13     double dayprice;                       //每天喝的价格,类似于单价
14 };
15 
16 bool cmp(Milk a, Milk b)
17 {
18      if (a.dayprice != b.dayprice)
19         return a.dayprice < b.dayprice;
20      else
21          return a.volume > b.volume;    //"单价"相同时,比较体积
22 }
23 int main()
24 {
25     int T;
26     scanf("%d", &T);
27     while (T--)
28     {
29         vector<Milk> mv;
30         int n;
31         scanf("%d", &n);
32         for (int i = 0; i < n; ++i)
33         {
34             Milk t;
35             cin >> t.brand >> t.price >> t.volume;
36             t.days = t.volume / everyday_v;
37             if (t.days >= 5)
38                t.days = 5;
39             t.dayprice = (double)t.price / t.days;
40             if (t.volume >= everyday_v)
41                 mv.push_back(t);
42         }
43         sort(mv.begin(), mv.end(), cmp);
44         cout << mv[0].brand << endl;
45     }
46     system("pause");
47     return 0;
48 }
原文地址:https://www.cnblogs.com/PegasusWang/p/2962353.html