Codeforces 1236A. Stones

传送门

注意到两种操作都要消耗中间的石头,并且两种操作每次都会得到 $3$ 个石头

那么显然优先做操作二是最优的,因为操作二只会消耗中间堆的一个石头

如果有剩下再进行操作 $1$ ,那么可以保证总操作次数最大,即答案最大

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
    return x*f;
}
int main()
{
    int T=read();
    while(T--)
    {
        int a=read(),b=read(),c=read(),ans=0;
        int t=min(b,c/2); ans+=t*3; b-=t;
        t=min(b/2,a); ans+=t*3;
        printf("%d\n",ans);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/LLTYYC/p/11699175.html