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

题目大意:

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

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

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

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

【猫一天就吃一份】

分析:

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

代码如下:

Codeforces 1154C Gourmet Cat 随笔 第1张
 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     Day(){}
56     Day(int x, int y, int z) : x(x), y(y), z(z){}
57 };
58 
59 int n, a, b, c, ans; 
60 vector< Food > foods[6] = {
61                             {Food(0, 0, 1), Food(0, 1, 0), Food(1, 0, 0)}, 
62                             {Food(2, 0, 0), Food(0, 1, 1), Food(1, 1, 0), Food(1, 0, 1)}, 
63                             {Food(2, 1, 0), Food(1, 1, 1), Food(1, 0, 2)}, 
64                             {Food(2, 2, 0), Food(2, 1, 1), Food(1, 1, 2)}, 
65                             {Food(2, 2, 1), Food(2, 1, 2), Food(1, 2, 2)}, 
66                             {Food(2, 2, 2), Food(3, 1, 2), Food(3, 2, 1)}
67                         };
68 
69 int main(){
70     cin >> a >> b >> c;
71     int t = min(min(a / 3, b / 2), c / 2);
72     
73     ans += 7 * t;
74     a -= 3 * t;
75     b -= 2 * t;
76     c -= 2 * t;
77     
78     rFor(i, 5, 0) {
79         foreach(j, foods[i]) {
80             if(a >= j->x && b >= j->y && c >= j->z) {
81                 a -= j->x; b -= j->y; c -= j->z;
82                 ans += i + 1;
83                 i = 0;
84                 break;
85             }
86             
87         }
88     }
89     
90     cout << ans << endl;
91     return 0;
92 }
View Code

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄