Educational Codeforces Round 91 (Rated for Div. 2) 参与排名人数6879 不熬夜打比赛的感觉真好
[codeforces 1380C] Create The Teams 自大到小排序后再分组
总目录详见https://blog.csdn.net/mrcrack/article/details/103564004
在线测评地址https://codeforces.com/contest/1380/problem/C
Problem | Lang | Verdict | Time | Memory |
---|---|---|---|---|
C - Create The Teams | GNU C++17 | Accepted | 61 ms | 4300 KB |
题目大意:将程序员分组,要求每组的值大于等于x,每组的值=每组程序员数量×该组中程序员最小技能值。注意:程序员可以不被选入组。要求分的组尽可能的多,输出组的数量。
此句很关键Each programmer should belong to at most one team. Some programmers may be left without a team.
样例模拟如下:
5 10
7 11 2 9 5
2
组1: 11
组1的值:11(技能)*1(数量)=11
组2: 9 7
组2的值:7(技能)*2(数量)=14
5,2技能对应的程序员不参与任何组。
4 8
2 4 2 3
1
组1: 4 3 2 2
组1的值:2(技能)*4(数量)=8
4 11
1 3 3 7
0
基本思路:自大到小排序后再分组
代码很快编好,提交AC.没想到1400分的题目这么简单。
AC代码如下:
#include <cstdio>
#include <algorithm>
#define maxn 100010
using namespace std;
int a[maxn];
int cmp(int a,int b){
return a>b;
}
int main(){
int t,n,x,i,tot,cnt;
scanf("%d",&t);
while(t--){
tot=0,cnt=0;
scanf("%d%d",&n,&x);
for(i=1;i<=n;i++)scanf("%d",&a[i]);
sort(a+1,a+1+n,cmp);//自大到小排序
for(i=1;i<=n;i++){
cnt++;//统计组内程序员数量
if(a[i]*cnt>=x)tot++,cnt=0;
}
printf("%d\n",tot);//统计组的数量
}
return 0;
}