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 KatrineYang at 2016-09-21 23:12:45 on Problem 3069
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main() {
	while(1){
		int r, n;
		scanf("%d%d", &r, &n);
		if(!(~r) && !(~n)) {
			break;
		}
		int ns[1010];
		for(int i = 0; i < n; i++) scanf("%d", &ns[i]);
		sort(ns, ns+n);
		int offset = 0, cnt = 0;
		while(offset < n){
			int zuo = offset;
			int pos = offset;
			for(; pos < n && ns[pos] <= ns[zuo]+r; pos++){
				;
			}
			cnt++;
			offset = pos;
			for(; offset < n && ns[offset] <= ns[pos-1]+r; offset++){
				;
			}
		}
		printf("%d\n", cnt);
	}
	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