A
来源:互联网 发布:oracle数据库cache 编辑:程序博客网 时间:2024/06/10 11:43
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.)
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.
For each test case, output the answer of the question.
23 10100 99 903 10000 0 0
23
题目大意:在火车上需要给手机充电,现在有一个容量为power的充电宝给手机充电问最多能充多少个?
代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include<set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
int a[105];
bool cmp(int x,int y)
{
return x<y;
}
int main()
{
int repeat;
while(scanf("%d",&repeat)!=EOF)
{
while(repeat--)
{
int num,power;
int count1=0;
scanf("%d%d",&num,&power);
for(int i=0;i<num;i++)
scanf("%d",&a[i]);
sort(a,a+num,cmp);//这里就是对那些手机的剩余电进行排序
for(int i=num-1;i>=0;i--){
if(a[i]==100)
count1++;
else
if((power+a[i])>=100){
count1++;
power=power-(100-a[i]);
}
}
printf("%d\n",count1);
}
}
return 0;
}
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- A
- A*
- a
- A
- a
- 简述计算机随机数生成原理
- 十分钟讲明白, golang, Go 语言切片(Slice)
- sql查询时间戳转时间字符串
- aiohttp遇到非法字符的处理(UnicodeDecodeError: 'utf-8' codec can't decode bytes in position......)
- fastjson的使用
- A
- STM32串口第一个字节丢失问题的分析过程
- 递归
- 集合框架
- 16 创建高级联结
- 序列流(集合流) * 把n个流合并在一起读取
- SpringMVC RequestMapping用法详解
- iOS 开发 图片缩略图的生成,展示图片中间一部分
- tensorflow 学习笔记12 循环神经网络RNN LSTM结构实现MNIST手写识别