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

posted @ 2016-01-19 22:39  Simon_X  阅读(430)  评论(0编辑  收藏  举报