-
Notifications
You must be signed in to change notification settings - Fork 0
/
POJ3069.cpp
49 lines (48 loc) · 1.34 KB
/
POJ3069.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{
int r,n;
vector<int> pos;
set<int> visited;
while(( cin >> r >> n ) && r != -1)
{
visited.clear();
pos.resize(n);
for( int i = 0; i < n; i++ )
cin >> pos[i];
sort(pos.begin(),pos.end());
int tempmax = -1, cnt = 0;
for( int i = 0; i < n; i++ )
{
if(visited.find(i)==visited.end())
{
if(pos[i] <= tempmax)
{
visited.insert(i);
}
else
{
cnt++;
tempmax = pos[i] + r;
//cout<<"Pos:"<<pos[i]<<endl;
for(int j = 1 ; i + j < n; j++ )
{
if(pos[i + j] - r <= pos[i])
{
visited.insert(i + j);
tempmax = pos[i + j] + r;
//cout<<"Move to:"<<pos[i + j]<<endl;
//cout<<"Max:"<<tempmax<<endl;
}
else j = n;
}
}
}
}
cout<<cnt<<endl;
}
}