Codeforces Round #552 (Div. 3)C. Gourmet Cat【枚举】

 Codeforces Round #552 (Div. 3)C. Gourmet Cat【枚举】_第1张图片

思路:范围很小,所以可以枚举一下星期几开始,我是先将第一周的情况算一下,然后算出来中间可以坚持多少周,然后再对最后一周进行分析就行了,比赛时写的代码有点乱。

#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1|1
const int maxn = 1e2 + 10;
const int inf = 0x3f3f3f3f;
int mp[10] = {0, 1, 2, 3, 1, 3, 2, 1};

int main()
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    int ans = 0;
    int a1, b1, c1;
    for(int i = 1; i <= 7; ++i)
    {
        int ans1 = 0;
        a1 = a, b1 = b, c1 = c;
        for(int j = i; j <= 7; ++j)
        {
            if(a1 < 0 || b1 < 0 || c1 < 0)
                break;
            if(mp[j] == 1)
                a1--;
            else if(mp[j] == 2)
                b1--;
            else if(mp[j] == 3)
                c1--;
            if(a1 >= 0 && b1 >= 0 && c1 >= 0)
                ans1++;
        }
        int cnt = a1 / 3;
        cnt = min(cnt, b1/2);
        cnt = min(cnt, c1/2);
        a1 -= cnt * 3;
        b1 -= cnt * 2;
        c1 -= cnt * 2;
        ans1 += cnt * 7;
        int aa = a1, bb = b1, cc = c1;
        for(int j = 1; j <= 7; ++j)
        {
            if(aa < 0 || bb < 0 || cc < 0)
                break;
            if(mp[j] == 1)
                aa--;
            else if(mp[j] == 2)
                bb--;
            else if(mp[j] == 3)
                cc--;
            if(j == 7)
                j == 0;
            if(aa >= 0 && bb >= 0 && cc >= 0)
                ans1++;
        }
        ans = max(ans, ans1);
    }
    cout << ans << endl;
    return 0;
}

 

你可能感兴趣的:(CF)