Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一次ac纪念一下,不过有点慢,用了94ms,毕竟是排序过的⊙﹏⊙b汗#include <cstdio> #include <cstring> int people[1001]; int Max_num=0; void Count_sort(int *arr,int arr_size) { int temp[100001]; memset(temp,0,sizeof(temp)); for (int i=0;i!=arr_size;++i) { ++temp[arr[i]]; } int j=0; for (int i=0;i<=Max_num;++i) { while(temp[i]!=0) { arr[j]=i; --temp[i]; ++j; } } } int main() { int T,t=1; scanf("%d",&T); while(T--) { printf("Scenario #%d:\n",t++); int need,n,sum=0; scanf("%d%d",&need,&n); Max_num=0; for (int i=0;i!=n;++i) { scanf("%d",&people[i]); sum+=people[i]; if(people[i]>Max_num)Max_num=people[i]; } if(sum<need)printf("impossible\n"); else { Count_sort(people,n); int ans=0,sum=0; while(sum<need) { sum+=people[--n]; ++ans; } printf("%d\n",ans); } if(T!=0)printf("\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator