A11952 | Sonya and Hotels
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $n$ hotels, where the $i$ -th hotel is located in the city with coordinate $x_i$ . 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$ .
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$ -th hotel is located in the city with coordinate $x_i$ . 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$ .
输入格式
The first line contains two integers $n$ and $d$ ( $1\leq n\leq 100$ , $1\leq d\leq 10^9$ ) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ( $-10^9\leq x_i\leq 10^9$ ) — coordinates of Sonya's hotels.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ( $-10^9\leq x_i\leq 10^9$ ) — coordinates of Sonya's hotels.
输出格式
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 $d$ .
输入输出样例
输入 #1
4 3 -3 2 9 16
输出 #1
6
输入 #2
5 2 4 8 11 18 19
输出 #2
5
In the first example, there are $6$ 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 $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$ , $6$ , $13$ , $16$ , and $21$ .
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$ , $6$ , $13$ , $16$ , and $21$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted