Sonya and Robots(CodeForces 1004A)

Description

Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.

The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has nn hotels, where the i-th hotel is located in the city with coordinate xi. Sonya is a smart girl, so she does not open two or more hotels in the same city.

Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to d. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel.

Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original n hotels to the new one is equal to d.

Input

The first line contains two integers nn and dd (1≤n≤100, 1≤d≤10^9) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.

The second line contains nn different integers in strictly increasing order x1,x2,…,xn (−10^9≤xi≤10^9) — coordinates of Sonya's hotels.

Output

Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to dd.

Sample Input

Input

4 3
-3 2 9 16

Output

6

Input

5 2
4 8 11 18 19

Output

5

Hint

In the first example, there are 66 possible cities where Sonya can build a hotel. These cities have coordinates −6, 5, 6, 12, 13, and 19.

In the second example, there are 55 possible cities where Sonya can build a hotel. These cities have coordinates 2, 6, 13, 16, and 21.

题解:很水很水的一道题,懂题意就可以直接a,傻傻的我还在翻译上卡了很久(哭.......   题意是在规定区域内建房子,问可能的情况的个数,就是遍历一遍,把所有的可能全部存入一个数组,然后去重,记得判断一下连续n个中无法建房的情况。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<utility>
#include<list>
#include<algorithm>
#define max(a,b)   (a>b?a:b)
#define min(a,b)   (a<b?a:b)
#define swap(a,b)  (a=a+b,b=a-b,a=a-b)
#define memset(a,v)  memset(a,v,sizeof(a))
#define X (sqrt(5)+1)/2.0
#define Pi acos(-1)
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e-8
#define ll long long
using namespace std;


ll a[222],b[2222];
int main()
{
    int n;
    ll d;
    cin>>n>>d;
    for(int i=0; i<n; i++)
        cin>>a[i];
    sort(a,a+n);
    int ans=2;
    int l=0;
    for(int i=1; i<n; i++)
    {
        if(a[i-1]+d<=a[i]-d)
        {
            b[l++]=a[i-1]+d;
            b[l++]=a[i]-d;
        }
    }
    sort(b,b+l);
    for(int i=0; i<n-1; i++)
        if(a[i]+d<=a[i+1]-d)
        {
            ans++;
            break;
        }
    for(int i=1; i<l; i++)
        if(b[i]!=b[i-1])
            ans++;
    cout<<ans<<endl;
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值