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

发个短点的程序

Posted by 407811696 at 2011-04-09 07:32:12 on Problem 3618
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define M 50005
#define INF 100000000
using namespace std;
int n,m,a[M];
bool cmp(const int t1,const int t2)
{
	return abs(double(t1))<abs(double(t2));
}
int main()
{
//	freopen("1.txt","r",stdin);
	while(scanf("%d%d",&m,&n)!=EOF)
	{
		int i,j,k,p=0;
		for(i=1,j=INF;i<=n;i++)
			scanf("%d",&a[i]);
		sort(a+1,a+1+n,cmp);
		for(i=1;i<=n;i++)
		{
			p+=abs(a[i]-a[i-1]);
			if(p>m)
				break;
		}
		printf("%d\n",i-1);
	}
	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