Gourmet Cat
Posted karshey
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Gourmet Cat相关的知识,希望对你有一定的参考价值。
Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food:
on Mondays, Thursdays and Sundays he eats fish food;
on Tuesdays and Saturdays he eats rabbit stew;
on other days of week he eats chicken stake.
Polycarp plans to go on a trip and already packed his backpack. His backpack contains:
a daily rations of fish food;
b daily rations of rabbit stew;
c daily rations of chicken stakes.
Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally.
Input
The first line of the input contains three positive integers a, b and c (1≤a,b,c≤7⋅108) — the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly.
Output
Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally.
Examples
Input
2 1 1
Output
4
Input
3 2 2
Output
7
Input
1 100 1
Output
3
Input
30 20 10
Output
39
Note
In the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the cat will eat fish food, during Tuesday — rabbit stew and during Wednesday — chicken stake. So, after four days of the trip all food will be eaten.
In the second example Polycarp can start his trip in any day of the week. In any case there are food supplies only for one week in Polycarps backpack.
In the third example Polycarp can start his trip in any day, excluding Wednesday, Saturday and Sunday. In this case, the cat will eat three different dishes in three days. Nevertheless that after three days of a trip there will be 99 portions of rabbit stew in a backpack, can cannot eat anything in fourth day of a trip.
先求有几周,再求一周内可以吃的最大天数(循环枚举)
注意每一次从某天开始枚举的时候g要重新赋值。
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
//1 2 3 4 5 6 7
//a b c a c b a
long long int a,b,c,ans=0,maxx=-1;
cin>>a>>b>>c;
//大于一周
if(a>=3&&b>=2&&c>=2)
{
long long int t=min(a/3,min(b/2,c/2));
ans=7*t;
a-=3*t;
b-=2*t;
c-=2*t;
}
//不足一周 一周后的每天枚举
int date[7]={0,1,2,0,2,1,0};
long long int g[3],sum=0;
for(int i=0;i<7;i++)
{
sum=0;
g[0]=a;//每一次重新枚举g都要重新赋值
g[1]=b;
g[2]=c;
for(int j=i;;j++)
{
if(g[date[j%7]]>0)
{
g[date[j%7]]--;
sum++;
}
else break;
}
maxx=max(maxx,sum);
}
cout<<ans+maxx;
return 0;
}
以上是关于Gourmet Cat的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #552 (Div. 3) Editorial 1154C - Gourmet Cat