Codeforces Round #552 (Div. 3)-C-Gourmet Cat

http://codeforces.com/contest/1154/problem/C

题意:

有一只猫,周一周四周日吃鱼肉,周二周六吃兔肉,周三周五吃鸡肉,现给出三种肉的数量,问最多能吃多少天?

解题:

先看看这些肉最多能支撑多少个完整周,必然会有最少的一样肉求模后很小,多出来的肉从周一到周日暴力循环,接在完整周的前后。

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<vector>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;

/**
1 4 7鱼肉
2 6 兔子
3 5 鸡肉
输入 a,b,c分别表示鱼肉,兔肉,鸡肉的天数
%7
0 3 6 鱼肉
1 5 兔肉
2 4 鸡肉
*/
int a,b,c;
int main()
{
    while(scanf("%d%d%d",&a,&b,&c)!=EOF)
    {
        int x[3];
        x[0]=a/3;
        x[1]=b/2;
        x[2]=c/2;
        int minn=min(x[0],min(x[1],x[2])); ///最少支撑的周数
        int r[3];
        r[0]=a-minn*3;
        r[1]=b-minn*2;
        r[2]=c-minn*2;
        int maxx=-inf;
        for(int i=0;i<7;i++)///i表示周几开始循环
        {
            int sum=minn*7;
            int temp0=r[0];
            int temp1=r[1];
            int temp2=r[2];
            for(int j=i;;j++)///j是第几天
            {
                int k=j%7;///当前周几
                if(k==0 || k==3 || k==6)
                {
                    if(temp0)
                    {
                        temp0--;
                        sum++;
                    }
                    else
                        break;
                }
                else if(k==1 || k==5)
                {
                    if(temp1)
                    {
                        temp1--;
                        sum++;
                    }
                    else break;
                }
                else
                {
                    if( temp2 )
                    {
                        temp2--;
                        sum++;
                    }
                    else
                        break;
                }
            }
            maxx=max(maxx,sum);
        }
        printf("%d\n",maxx);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/shoulinniao/p/10833788.html