Codeforces 1154C Gourmet Cat

时间:2023-03-09 04:09:18
Codeforces 1154C Gourmet Cat

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

题目大意:

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

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

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

【猫一天就吃一份】

分析:

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

代码如下:

 #include <bits/stdc++.h>
using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i) #define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl #define LOWBIT(x) ((x)&(-x)) #define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin()) #define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a)) #define pii pair<int,int>
#define piii pair<pair<int,int>,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second inline int gc(){
static const int BUF = 1e7;
static char buf[BUF], *bg = buf + BUF, *ed = bg; if(bg == ed) fread(bg = buf, , BUF, stdin);
return *bg++;
} inline int ri(){
int x = , f = , c = gc();
for(; c<||c>; f = c=='-'?-:f, c=gc());
for(; c>&&c<; x = x* + c - , c=gc());
return x*f;
} typedef long long LL;
typedef unsigned long long uLL;
const double EPS = 1e-;
const int inf = 1e9 + ;
const LL mod = 1e9 + ;
const int maxN = 1e5 + ;
const LL ONE = ; struct Food{
int x, y, z;
}; int n, a, b, c, ans;
vector< Food > foods[] = {
{Food(, , ), Food(, , ), Food(, , )},
{Food(, , ), Food(, , ), Food(, , ), Food(, , )},
{Food(, , ), Food(, , ), Food(, , )},
{Food(, , ), Food(, , ), Food(, , )},
{Food(, , ), Food(, , ), Food(, , )},
{Food(, , ), Food(, , ), Food(, , )}
}; int main(){
cin >> a >> b >> c;
int t = min(min(a / , b / ), c / ); ans += * t;
a -= * t;
b -= * t;
c -= * t; rFor(i, , ) {
foreach(j, foods[i]) {
if(a >= j->x && b >= j->y && c >= j->z) {
a -= j->x; b -= j->y; c -= j->z;
ans += i + ;
i = ;
break;
} }
} cout << ans << endl;
return ;
}