A10343 | Home Numbers
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The main street of Berland is a straight line with $n$ houses built along it ( $n$ is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from $1$ to $n-1$ in the order from the beginning of the street to the end (in the picture: from left to right). The houses with even numbers are at the other side of the street and are numbered from $2$ to $n$ in the order from the end of the street to its beginning (in the picture: from right to left). The corresponding houses with even and odd numbers are strictly opposite each other, that is, house $1$ is opposite house $n$ , house $3$ is opposite house $n-2$ , house $5$ is opposite house $n-4$ and so on.
Vasya needs to get to house number $a$ as quickly as possible. He starts driving from the beginning of the street and drives his car to house $a$ . To get from the beginning of the street to houses number $1$ and $n$ , he spends exactly $1$ second. He also spends exactly one second to drive the distance between two neighbouring houses. Vasya can park at any side of the road, so the distance between the beginning of the street at the houses that stand opposite one another should be considered the same.
Your task is: find the minimum time Vasya needs to reach house $a$ .
Vasya needs to get to house number $a$ as quickly as possible. He starts driving from the beginning of the street and drives his car to house $a$ . To get from the beginning of the street to houses number $1$ and $n$ , he spends exactly $1$ second. He also spends exactly one second to drive the distance between two neighbouring houses. Vasya can park at any side of the road, so the distance between the beginning of the street at the houses that stand opposite one another should be considered the same.
Your task is: find the minimum time Vasya needs to reach house $a$ .
输入格式
The first line of the input contains two integers, $n$ and $a$ ( $1<=a<=n<=100000$ ) — the number of houses on the street and the number of the house that Vasya needs to reach, correspondingly. It is guaranteed that number $n$ is even.
输出格式
Print a single integer — the minimum time Vasya needs to get from the beginning of the street to house $a$ .
输入输出样例
输入 #1
4 2
输出 #1
2
输入 #2
8 5
输出 #2
3
In the first sample there are only four houses on the street, two houses at each side. House $2$ will be the last at Vasya's right.
The second sample corresponds to picture with $n=8$ . House $5$ is the one before last at Vasya's left.
The second sample corresponds to picture with $n=8$ . House $5$ is the one before last at Vasya's left.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted