2018广西省赛 . Team Name(暴力求解)

问题 C: Team Match

时间限制: 1 Sec  内存限制: 128 MB
提交: 104  解决: 37
[提交] [状态] [讨论版] [命题人:admin]

题目描述

The programming competition not only depends on the programmers, but also directed by the coaches. Mr Z is a coach who direct n players to take part in the Guangxi Province Collegiate Programming Contest. We assume that a team is consisted of 3 players whose ability is x, y, z respectively and x >= y >= z. Then the team’s total ability is 3 * x + 2 * y + 1 * z; And for a team, if its ability is not lower than the gold medal level m, the team will certainly win the gold medal. Mr Z would like to match teams to gain as many gold medals as possible, could you tell him how many gold medals it is?

 

输入

The first line is an integer T which indicates the case number.
And as for each case, there will be 2 lines.
In the first line, there are 2 integers n m, which indicate the number of players, the gold medal level respectively. Please remember n is always the multiple of 3.
In the second line, there are n integers which represents everyone’s ability.
It is guaranteed that——
T is about 100.
for 100% cases, 1 <= n <= 15, 1 <= m <= 30, 1 <= a[i] <= 20.

 

输出

As for each case, you need to output a single line.
There should be an integer in the line which means the gold medal teams Mr Z could match.

 

样例输入

2
6 18
3 3 3 4 2 2
6 7
1 1 1 1 1 1

 

样例输出

2
0

解题思路:暴力求解


#include<bits/stdc++.h>
using namespace std;
#define maxn 20
#define M(a) memset(a,0,sizeof(a))

struct node{
    int val;
    int vis;
} a[maxn];


bool cmp(node a,node b){
    return a.val>b.val;
}

int main()
{
    int t,n,m;
    cin>>t;
    while(cin>>n>>m)
    {
        int ans=0;
        for(int i=0; i<n; i++){
            cin>>a[i].val;
            a[i].vis=0;
        }
        sort(a,a+n,cmp);

        for(int i=0; i<n; i++){
            int b=-1,c=-1,d=-1;
            if(a[i].vis) continue;
            for(int j=i+1; j<n; j++)
            {
                if(a[j].vis) continue;
                for(int k=j+1; k<n; k++){
                    if(a[k].vis) continue;
                    else{
                        if(3*a[i].val+2*a[j].val+a[k].val>=m){
                            b=i,c=j,d=k;
                        }
                    }
                }
            }
            if(b==-1) break;
            else{
                a[b].vis=a[c].vis=a[d].vis=1;
                ans++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值