第六届福建省大学生程序设计竞赛 Problem A Super Mobile Charger【模拟】

Problem A Super Mobile Charger

 

Accept: 209    Submit: 391

Time Limit: 1000 mSec    Memory Limit : 32768 KB

Problem Description

While HIT ACM Group finished their contest in Shanghai and is heading back Harbin, their train was delayed due to the heavy snow. Their mobile phones are all running out of battery very quick. Luckily, zb has a super mobile charger that can charge all phones.

There are N people on the train, and the i-th phone has p[i] percentage of power, the super mobile charger can charge at most M percentage of power.

Now zb wants to know, at most how many phones can be charged to full power. (100 percent means full power.)

Input

The first line contains an integer T, meaning the number of the cases (1 <= T <= 50.).

For each test case, the first line contains two integers N, M(1 <= N <= 100,0 <= M <= 10000) , the second line contains N integers p[i](0 <= p[i] <= 100) meaning the percentage of power of the i-th phone.

Output

For each test case, output the answer of the question.

Sample Input

2

3 10

100 99 90

3 1000

0 0 0

Sample Output

2

3

题目大意:

有电能为M的充电宝,和N个剩余电量的手机,问充电宝最多能把几个手机充到满电。

解题思路:

排序从用数组存一下和100的差值,从小到大排序。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; 
int map[10000];
bool cmp(int n,int y)
{
	return n<y;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		int m;
		scanf("%d%d",&n,&m);
		int i,j;
		for(i=0;i<n;i++)
		{
			int yy;
			scanf("%d",&yy);
			map[i]=100-yy;
		}
		int ans=0;
		sort(map,map+n,cmp);
		for(i=0;i<n;i++)
		{
			if(m-map[i]>=0)
			{
				ans++;
				m-=map[i];
			}
		}
		printf("%d\n",ans);
	}
	return 0; 
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值