POJ3069-Saruman's Army-贪心水题

不断选距离一个点右侧不超过R的点  为 标记点即可


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define INF 0x7f7f7f7f
const __int64 maxn = 200005; 

 int tm[1005];
 int r,n;
int main()
{  
	int i;
	while (cin>>r>>n)
	{
		if (r==-1&&n==-1)
			break;
		for (i=1;i<=n;i++)
		{
			scanf("%d",&tm[i]);
		}
		sort(tm+1,tm+1+n);/*
		for (i=1;i<=n;i++)
			printf( "%d ",tm[i]);*/
		int x=tm[1]+r;
		int cun=0;
		int flag=0;
		int line=0;
		tm[n+1]=INF;
		for (i=1;i<=n+1;i++)
		{
			if (x>=tm[i]) 
				continue;
			if (line==0)
			{
			i--;
			cun++;
			x=tm[i]+r;
			line=1; 
			
			}
			else
			{
				x=tm[i]+r;
				line=0; 
			}

		}
		 
		 
		printf("%d\n",cun);

	}
	
	return 0;
}


你可能感兴趣的:(POJ3069-Saruman's Army-贪心水题)