Codeforces Round #593 (Div. 2) A. Stones

Link
题意:
\(a,b,c\) 三堆石头,现在有个操作
操作一:从 \(a\) 中拿一块石头,从 \(b\) 中拿两块石头
操作二:从 \(b\) 中拿一块石头,从 \(c\) 中拿两块石头
问最多拿几块石头
思路:
贪心
两种操作收益都是 \(3\) 且都会消耗 \(b\)
操作 \(2\)\(b\) 消耗较小 则可优先选择操作二再进行操作一即可得到最大值
代码:

#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    //freopen("in.txt","r",stdin);
    int T;cin>>T;
    while(T--)
    {
        int a,b,c;
        cin>>a>>b>>c;
        int res=min(b,c>>1)*3;
        b-=res/3;
        res+=min(a,b>>1)*3;
        cout<<res<<endl;
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/c4Lnn/p/12398337.html