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 brivia at 2018-05-10 11:13:44 on Problem 3069
//poj2306

#include<stdio.h>
#define MAXN 1010

int X[MAXN];
int R, n;

void read_data(int n);
void solve(void);

int main(int argc, char* argv[])
{
	while(scanf("%d %d", &R, &n) && R != -1)
	{
		read_data(n);
		solve();
	}
}

void read_data(int n)
{
	int temp;
	for(int i = 0; i < MAXN; ++i)
		X[i] = 0;
	for(int i = 0; i < n; ++i)
	{
		scanf("%d", &temp);
		X[temp] = 1;
	}
}

void solve(void)
{
	int ans = 0;
	int start, mid, end;
	for(int i = 0; i < MAXN; ++i)
	{
		if(X[i] != 0)
		{
			ans++;
			start = i;
			mid = i + R;
			while(X[mid] == 0) mid--;
			for(int j = start; j <= mid+R; j++)
				X[j] = 0;
		}
	}
	printf("%d\n", ans);
}

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