ARC126A - Make 10 思维

该博客讨论了一种编程问题,即如何用给定数量的2、3和4来组合出最多的10。通过分析,得出3总是成对出现,转化为6的数量。博主提供了详细的思路和代码实现,包括优先考虑6,然后处理2和4,以最大化组合10的数量。
摘要由CSDN通过智能技术生成

A-Make 10

题意:

给你n1,n2,n3个2,3,4。问你最多能凑出来多少个10?

思路:

显然只有442 433 3322 4222 22222五种凑法,注意到3一定是成对出现,所以把3的数量除以2,变为6的数量,并优先考虑6.

具体见注释

// Decline is inevitable, romance will last forever.
//ARC126A-make 10
//#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cstdio>
using namespace std;
#define mst(a, x) memset(a, x, sizeof(a))
#define INF 0x3f3f3f3f
#define P 998244353
#define int long long
const int maxn = 2e5 + 10;
const int maxm = 3e5*4 + 10;

void solve() {
    int a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    b >>= 1;
    int d = a + c/2;
    if(b >= c + a/2) {  //若6的数量比2的数量/2和4的数量加起来还多,则直接输出
        cout << c + a/2 << '\n';
        return;
    }
    ans = b;    //下面考虑6能够用完的情况 ans先等于6的数量
    if(c >= ans) c-= ans;   //如果4的数量比6的数量多 则仅用4就能凑出来b个10
    else a -= 2*(ans-c),c = 0;  //否则把所有4都用完,再用掉一部分2,凑出b个10
    if(c >= a*2) {  //如果此时还能凑出来442 则凑完 这时仅剩下4了 凑不出10了
        ans += a;
    }
    else {
        int tmp = c/2;  //否则先把442凑完
        c -= tmp*2, a-=tmp;
        ans += tmp;
        ans += (c*4+a*2)/10;    //此时剩下的4数量为0or1,2可能剩下很多
    }
    cout << ans << endl;
}
signed main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//    int T; scanf("%d", &T); while(T--)
    int T; cin >> T; while(T--)
    solve();
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值