Super Mobile Charger FZU

来源:互联网 发布:js string转int 编辑:程序博客网 时间:2024/04/29 05:37

Super Mobile Charger

 FZU - 2212 

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
23 10100 99 903 10000 0 0
Sample Output
23
         这个题的意思是:先有t组测试用例,每组给你手机的个数n与充电站能提供的电量x,再给你n个手机的电量p【1】……
p     P【n】,问给这些手机充电后,最多能充满几个手机,输出个数。
1 这个题纯粹的贪心,先由大到小进行排序,然后进行逐个充电最后计算个数。
Select Code
#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;int main(){int t;scanf("%d",&t);while(t--){int a[110];int n,m;scanf("%d%d",&n,&m);for(int i=0;i<n;i++){scanf("%d",&a[i]); }  sort(a,a+n); int ans=0; for(int i=n-1;i>-1;i--) { if(m>0) { if(100-a[i]<=m) m=m-(100-a[i]),ans++; if(100-a[i]>m) break; } if(m<=0) break; } printf("%d\n",ans);} } 



原创粉丝点击