第六届福建省大学生程序设计竞赛-重现赛(感谢承办方华侨大学)Problem A Super Mobile Charger
2015-12-28 15:51
555 查看
Problem A Super Mobile Charger
Accept: 217 Submit: 402
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.
2
3 10
100 99 90
3 1000
0 0 0
2
3
题意:你有一个超级充电宝,别人的充电宝充到100%就满了,问你可以给几个人充满电。
思路:电量从大到小排序,算最多能给几个人充,ps:对方电满的话也算充了1个。
ac-code:
Accept: 217 Submit: 402
Time Limit: 1000 mSec Memory Limit : 32768 KB
![](http://acm.fzu.edu.cn/image/prodesc.gif)
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.)
![](http://acm.fzu.edu.cn/image/prodesc.gif)
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.
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Output
For each test case, output the answer of the question.
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Sample Input
23 10
100 99 90
3 1000
0 0 0
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Sample Output
23
题意:你有一个超级充电宝,别人的充电宝充到100%就满了,问你可以给几个人充满电。
思路:电量从大到小排序,算最多能给几个人充,ps:对方电满的话也算充了1个。
ac-code:
#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> using namespace std; bool cmp(int a, int b) { return a > b; } int p[105]; int main() { int t; scanf("%d", &t); while(t--) { int n,m; scanf("%d%d", &n, &m); int i,j,k; for(i = 0; i < n; i++) scanf("%d", &p[i]); int sum = 0; sort(p, p+n,cmp); for(i = 0 ; i < n; i++) { if(p[i]==100) sum++; else{ m = m-(100-p[i]); sum++; if(m < 0){ sum--; break; } } } printf("%d\n", sum); } return 0; }
相关文章推荐
- 12.28 AJAX 返回XML值
- 高性能 js -- 无阻塞加载脚本
- iOS 播放音效
- web中各种路径的获取
- find搜索命令
- MyBatis插入及查询获取自增主键二选一的方法
- android中的样式与主题(一、二)
- Dijkstra算法--寻找最短路径
- 工信部备案-公安备案
- Spark Streaming实例分析
- 数据结构线性表相关操作
- 高质量C++编程之第1章 文件结构
- UVa 679 Droppintg Balls (小球下落)
- RubyGems 镜像 - 淘宝网 和第三方库Cocoapods安装
- Android TextView部分字体变色或字体变大小
- 82、冗余网关配置实验之HSRP
- 关于浏览器访问本地文件系统
- Linux抓包工具tcpdump详解
- Fedora 22安装ffmpeg-devel
- 装修日记