Codeforces 1154C Gourmet Cat

题目链接:http://codeforces.com/problemset/problem/1154/C

题目大意:

主人有一只猫。
周一&周四&周日:吃鱼
周二&周六:吃兔子
周三&周五:吃鸡

他们现在要外出旅游。他们带了一个包,包里有:
a份鱼肉
b份兔肉
c份鸡肉

问,猫的主人在最优解的情况下(即他可以自由的选择周几出去旅游),最多可以多少天不额外在外购买猫粮?(即,这个包最多能够猫吃多少天)

【猫一天就吃一份】

分析:

  首先把能吃完整7天的食量减掉,接下来的食物配比就只能吃0~6天了,可以把满足能吃i(0 < i < 7)天的所有实物配比情况全部列出来,再枚举,能大大减少代码量。

代码如下:

 

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 #define rep(i,n) for (int i = 0; i < (n); ++i)
 5 #define For(i,s,t) for (int i = (s); i <= (t); ++i)
 6 #define rFor(i,t,s) for (int i = (t); i >= (s); --i)
 7 #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
 8 #define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i)
 9 
10 #define pr(x) cout << #x << " = " << x << "  "
11 #define prln(x) cout << #x << " = " << x << endl
12 
13 #define LOWBIT(x) ((x)&(-x))
14 
15 #define ALL(x) x.begin(),x.end()
16 #define INS(x) inserter(x,x.begin())
17 
18 #define ms0(a) memset(a,0,sizeof(a))
19 #define msI(a) memset(a,inf,sizeof(a))
20 #define msM(a) memset(a,-1,sizeof(a))
21 
22 #define pii pair<int,int> 
23 #define piii pair<pair<int,int>,int> 
24 #define mp make_pair
25 #define pb push_back
26 #define fi first
27 #define se second
28 
29 inline int gc(){
30     static const int BUF = 1e7;
31     static char buf[BUF], *bg = buf + BUF, *ed = bg;
32     
33     if(bg == ed) fread(bg = buf, 1, BUF, stdin);
34     return *bg++;
35 } 
36 
37 inline int ri(){
38     int x = 0, f = 1, c = gc();
39     for(; c<48||c>57; f = c=='-'?-1:f, c=gc());
40     for(; c>47&&c<58; x = x*10 + c - 48, c=gc());
41     return x*f;
42 }
43 
44 typedef long long LL;
45 typedef unsigned long long uLL;
46 const double EPS = 1e-9;
47 const int inf = 1e9 + 9;
48 const LL mod = 1e9 + 7;
49 const int maxN = 1e5 + 7;
50 const LL ONE = 1;
51 
52 struct Food{
53     int x, y, z;
54 };
55 
56 int n, a, b, c, ans; 
57 vector< Food > foods[6] = {
58                             {Food(0, 0, 1), Food(0, 1, 0), Food(1, 0, 0)}, 
59                             {Food(2, 0, 0), Food(0, 1, 1), Food(1, 1, 0), Food(1, 0, 1)}, 
60                             {Food(2, 1, 0), Food(1, 1, 1), Food(1, 0, 2)}, 
61                             {Food(2, 2, 0), Food(2, 1, 1), Food(1, 1, 2)}, 
62                             {Food(2, 2, 1), Food(2, 1, 2), Food(1, 2, 2)}, 
63                             {Food(2, 2, 2), Food(3, 1, 2), Food(3, 2, 1)}
64                         };
65 
66 int main(){
67     cin >> a >> b >> c;
68     int t = min(min(a / 3, b / 2), c / 2);
69     
70     ans += 7 * t;
71     a -= 3 * t;
72     b -= 2 * t;
73     c -= 2 * t;
74     
75     rFor(i, 5, 0) {
76         foreach(j, foods[i]) {
77             if(a >= j->x && b >= j->y && c >= j->z) {
78                 a -= j->x; b -= j->y; c -= j->z;
79                 ans += i + 1;
80                 i = 0;
81                 break;
82             }
83             
84         }
85     }
86     
87     cout << ans << endl;
88     return 0;
89 }
View Code

 

posted @ 2019-04-18 20:14  梦樱羽  阅读(370)  评论(0编辑  收藏  举报
Live2D