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 13408100238 at 2014-08-08 08:56:45 on Problem 3069
#include"iostream"
#include"cstdio"
#include"cstring"
#include"algorithm"
using namespace std;
const int ms=1001;
int a[ms];
int r,n;
void solve()
{
	int i=0,ans=0,l;
	sort(a,a+n);
	l=a[0];
	while(i<n)
	{
		while(i<n&&l+r>=a[i])
			i++;
		l=a[i-1];
		while(i<n&&l+r>=a[i])
			i++;
		l=a[i];
		ans++;
	}
	printf("%d\n",ans);
	return ;
}
int main()
{
	while(scanf("%d%d",&r,&n)==2)
	{
		if(r==-1&&n==-1)
			break;
		for(int i=0;i<n;i++)
			scanf("%d",&a[i]);
		solve();
	}
	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