首页 > 其他 > 详细

[CF1313A] Fast Food Restaurant - 贪心

时间:2020-03-12 13:22:50      阅读:50      评论:0      收藏:0      [点我收藏+]

有一个集合,三种元素,每种分别有 \(a_i\) 个,求最多能分出的不同的不可重非空子集的个数

Solution

贪心,先取 \(1\) 个的,再取 \(2\) 个的,最后取 \(3\) 个的

#include <bits/stdc++.h>
using namespace std;

int a[4],n;

signed main() {
    ios::sync_with_stdio(false);
    cin>>n;
    while(n--) {
        cin>>a[1]>>a[2]>>a[3];
        int ans=0;
        for(int i=1;i<=3;i++) if(a[i]) --a[i],++ans;
        sort(a+1,a+4);
        if(a[2]&&a[3]) --a[2],--a[3],++ans;
        if(a[1]&&a[3]) --a[1],--a[3],++ans;
        if(a[1]&&a[2]) --a[1],--a[2],++ans;
        if(a[1]&&a[2]&&a[3]) ++ans;
        cout<<ans<<endl;
    }
}

[CF1313A] Fast Food Restaurant - 贪心

原文:https://www.cnblogs.com/mollnn/p/12468220.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!