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

Re:贪心大水题

Posted by 18792199768 at 2022-05-03 22:11:22 on Problem 3069
In Reply To:贪心大水题 Posted by:13408100238 at 2014-08-08 08:56:45
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int R, N;


int main()
{
	while (cin >> R >> N)
	{
		vector<int> data;
		if (R == -1 && N == -1)
			break;

		int x;
		for (int i = 0; i < N; i++)
		{
			cin >> x;
			data.push_back(x);
		}
		sort(data.begin(), data.end());

		int i = 0, ans = 0;
		while (i < N)
		{
			int s = data[i++];

			while (data[i] <= s + R && i < N)i++;

			int p = data[i - 1];

			while (data[i] <= p + R && i < N)i++;

			ans++;
		}

		cout << ans << "\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