题目描述
In a rural village in Thailand, there is a long, straight, road with houses scattered along it.
(We can picture the road as a long line segment, with an eastern endpoint and a western endpoint.) The Thai government is planning to set up bus stops on this road in such a way that every house is within ten kilometers of one of the stops. What is the minimum number of stops the government need to set up to satisfy the requirement?
输入
The first line contains a single integer m representing the number of the test cases. Eachtest case consists of the following two lines:
The first line contains a single integer n representing the number of houses on the road, where 0 ≤ n ≤ 2,000,000.
The second line contains n integers h1 h2 … hn representing the locations of the houses in kilometers as measured from the start of the road, where 0 ≤ hi ≤ 90,000,000. That is, the first house is h1 kilometers away from the start of the road, the second house is h2 kilometers
away from the start of the road, and so on. You may assume that hi ’s are sorted in ascending order, e.g., h1 ≤ h2 ≤ h3 ≤ … ≤ hn .
输出
For each test case, print out in a single line the minimum number of bus stops that satisfy the requirement.
样例输入
复制样例数据
2 5 1 2 3 200 210 4 10 30 80 200
样例输出
2 3
#include<iostream>
#include<map>
using namespace std;
typedef long long ll;
map<ll,ll>mapp;
ll a[2000010];
int main()
{
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
if(n==0)
cout<<"0"<<endl;
else
{
ll p;
ll s;
cin>>s;
ll sum=1;
for(ll i=1; i<n; i++)
{
cin>>p;
if(p>s+20)
{
sum++;
s=p;
}
else
{
continue;
}
}
cout<<sum<<endl;
}
}
return 0;
}