题目链接:http://acm.tju.edu.cn/toj/showp3982.html
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 416 Accepted Runs: 248
Z is planning to visit the Tourist Kingdom for M days. This kingdom is full of lovely cities. During his stay Z would like to visit as many different cities as possible. He cannot visit more than one city on the same day.
Additionally,different cities may require him to stay for a different number of days.For each i,city i counts as visited if Z spends at least d[i] days in the city.
Help Z find the maximal number of cities he can visit during his vacation.
Input
First a integer T,the number of test cases.For each test case,the first line is M and N,the total days Z has and the number of cities.(M,N≤50)
Then N integers,meaning the int[] d.
Output
The maximal number of cities Z can visit.
Sample Input
3 5 3 2 2 2 5 3 5 6 1 6 5 1 1 1 1 1
Sample Output
2 1 5
Source: TJU Team Selection 2013
水题,水的不能再水的题,排序然后贪心。说多了直接上代码好了。。。
#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
int n,m,t,city[51],sum;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
sum=0;
for(int i=0;i<m;i++)
scanf("%d",&city[i]);
sort(city,city+m);
for(int i=0;i<m;i++)
if(n>=city[i]){
sum++;
n-=city[i];
}
else
break;
printf("%d\n",sum);
}
}