水题 ZOJ 3875 Lunch Time

时间:2022-12-12 19:44:03

 

题目传送门

 1 /*  2  水题:找排序找中间的价格,若有两个,选价格大的;  3  写的是有点搓:)  4 */  5 #include <cstdio>  6 #include <iostream>  7 #include <algorithm>  8 #include <cmath>  9 #include <cstring>  10 #include <string>  11 #include <map>  12 #include <set>  13 #include <queue>  14 #include <vector>  15 using namespace std;  16  17 const int MAXN = 1e4 + 10;  18 const int INF = 0x3f3f3f3f;  19 struct S  20 {  21 char name[55];  22 int p;  23 }s[110];  24 struct M  25 {  26 char name[55];  27 int p;  28 }m[110];  29 struct D  30 {  31 char name[55];  32 int p;  33 }d[110];  34  35 bool cmp_s(S x, S y)  36 {  37 return x.p < y.p;  38 }  39  40 bool cmp_m(M x, M y)  41 {  42 return x.p < y.p;  43 }  44  45 bool cmp_d(D x, D y)  46 {  47 return x.p < y.p;  48 }  49  50 int main(void) //ZOJ 3875 Lunch Time  51 {  52 //freopen ("G.in", "r", stdin);  53  54 int t;  55 scanf ("%d", &t);  56 while (t--)  57  {  58 int a, b, c;  59 int tot = 0, s_id, m_id, d_id;  60  61 scanf ("%d%d%d", &a, &b, &c);  62 for (int i=1; i<=a; ++i)  63  {  64 scanf ("%s%d", &s[i].name, &s[i].p);  65  }  66 sort (s+1, s+1+a, cmp_s);  67 for (int i=1; i<=b; ++i)  68  {  69 scanf ("%s%d", &m[i].name, &m[i].p);  70  }  71 sort (m+1, m+1+b, cmp_m);  72 for (int i=1; i<=c; ++i)  73  {  74 scanf ("%s%d", &d[i].name, &d[i].p);  75  }  76 sort (d+1, d+1+c, cmp_d);  77  78 if (a & 1)  79  {  80 tot += s[(a+1)/2].p; s_id = (a+1) / 2;  81  }  82 else  83  {  84 int l = a / 2; int r = l + 1;  85 if (s[l].p < s[r].p)  86  {  87 tot += s[r].p; s_id = r;  88  }  89 else  90  {  91 tot += s[l].p; s_id = l;  92  }  93  }  94 if (b & 1)  95  {  96 tot += m[(b+1)/2].p; m_id = (b+1) / 2;  97  }  98 else  99  { 100 int l = b / 2; int r = l + 1; 101 if (m[l].p < m[r].p) 102  { 103 tot += m[r].p; m_id = r; 104  } 105 else 106  { 107 tot += m[l].p; m_id = l; 108  } 109  } 110 if (c & 1) 111  { 112 tot += d[(c+1)/2].p; d_id = (c+1) / 2; 113  } 114 else 115  { 116 int l = c / 2; int r = l + 1; 117 if (d[l].p < d[r].p) 118  { 119 tot += d[r].p; d_id = r; 120  } 121 else 122  { 123 tot += d[l].p; d_id = l; 124  } 125  } 126 127 printf ("%d %s %s %s\n", tot, s[s_id].name, m[m_id].name, d[d_id].name); 128  } 129 130 131 return 0; 132 } 133 134 /* 135 15 Fresh_Cucumber Fried_Vermicelli Steamed_Stuffed_Bun 136 108 West_Lake_Water_Shield_Soup DongPo's_Braised_Pork DongPo's_Crisp 137 */