FZU 2212 Super Mobile Charger(超级充电宝)

【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.)

HIT ACM队完成了上海的比赛正要回哈尔滨,谁知他们的火车却因大雪晚点了。他们的手机电量告急。不过没关系,zb随身携带了一个可以适配所有手机的超级充电宝。

火车上有N个人,第i个手机的剩余电量百分比为p[i],这个超级充电宝最多只能充百分之M的电量。

现在zb想知道,最多有多少部手机可以充满电。(百分百表示手机充满电。)

 

【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.

输入的首行是一个整数T表示测试样例的数量(1 <= T <= 50。)。

对于每个测试样例,第一行包含两个整数N,M(1 <= N <= 100,0 <= M <= 10000),第二行有N个整数p[i](0 <= p[i] <= 100)表示第i个手机的剩余电量百分百。

 

【Output】

【输出】

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

每个测试样例输出其最多充满电的手机数量。

 

【Sample Input - 输入样例】

【Sample Output - 输出样例】

2

3 10

100 99 90

3 1000

0 0 0

2

3

 

【题解】

一共有M的电,要充满尽可能多的手机,排个序,然后看看M能撑几部手机,输出结果,没了。

 1 #include<cstdio>
 2 #include<algorithm>
 3 int main(){
 4     freopen("1.txt", "r", stdin);
 5     int t, n, m, i, j, s, data[1005];
 6     scanf("%d", &t);
 7     while (t--){
 8         scanf("%d%d", &n, &m);
 9         for (s = i = 0; i < n; ++i) scanf("%d", &j), data[i] = j - 100;
10         std::sort(data, data + n);
11         for (--n; ~n; --n){
12             m += data[n];
13             if (m>0) ++s;
14             else break;
15         }
16         printf("%d\n", s);
17     }
18     return 0;
19 }

 FZU 2212

转载于:https://www.cnblogs.com/Simon-X/p/5143660.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值