Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一次ac纪念一下,不过有点慢,用了94ms,毕竟是排序过的⊙﹏⊙b汗

Posted by TSERROF at 2012-08-16 13:02:25 on Problem 2487
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator