Super Mobile Charger
2015-12-27 20:54
441 查看
Super Mobile Charger
Accept: 8 Submit: 24
Time Limit: 1000 mSec Memory Limit : 32768 KB
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.)
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
Source
第六届福建省大学生程序设计竞赛-重现赛(感谢承办方华侨大学) http://acm.fzu.edu.cn/problem.php?pid=2212 解题思路:比赛的大水题,由于自己第一次看错题目,第二次写排序时出问题导致wa了。大概思路就是先把n个数进行排序由大到小。然后在开始100-a[i]的差和m比较,如果m大于0的话就一直重复操作
#include <stdio.h> #include <stdlib.h> #include <math.h> #include<iostream> #include<algorithm> using namespace std; int cmp(int a,int b) { return a>b; } int main() { int t; cin>>t; while(t--) { int n,m; cin>>n>>m; int a[101]={0}; for(int i=0;i<n;i++) { cin>>a[i]; } sort(a,a+n,cmp); int tp=0; for(int i=0;i<n;i++) { m=m-(100-a[i]); if(m>=0) { tp++; } } cout<<tp<<endl; } return 0; }
相关文章推荐
- HDU 5240 Exam (好水的题)
- 北大—1006——Biorhythms
- 时间计算(heaven.pas/cpp)
- 工作依赖(job.cpp/pas)
- 题目 英雄 (BFS)
- kmp 学习 hihocoder #1015
- HDU 1096 A+B for Input-Output Practice (VIII)
- P1478
- P1035
- P1008 难度2.7
- 2020 绝对值排序
- 2021 发工资咯
- 2022 海选女主角
- 2024 C语言合法标识符
- 2025 查找最大元素
- 2026 首字母变大写
- 2027 统计元音
- 2028 Lowest Common Multiple Plus
- 2018 母牛的故事
- 2023 求平均成绩