CF638A.Home Numbers

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

伯兰德的主街是一条直线,沿街建有 nn 座房屋(nn 为偶数)。房屋分布在街道两侧:奇数编号的房屋位于街道一侧,按从街起点到终点的顺序编号为 1,3,5,…,n−11, 3, 5, \dots, n-1(图中:从左到右);偶数编号的房屋位于街道另一侧,按从街终点到起点的顺序编号为 2,4,6,…,n2, 4, 6, \dots, n(图中:从右到左)。奇偶编号房屋严格相对:即房屋 11 与房屋 nn 相对,房屋 33 与房屋 n−2n-2 相对,房屋 55 与房屋 n−4n-4 相对,依此类推。

瓦夏需要尽快到达编号为 aa 的房屋。他从街道起点出发,驾车驶向房屋 aa。从街道起点到达房屋 11 和房屋 nn 均恰好耗时 11 秒;行驶于任意两个相邻房屋之间也恰好耗时 11 秒。瓦夏可在道路任一侧停车,因此街道起点到一对相对房屋的距离视为相同。

你的任务是:求出瓦夏到达房屋 aa 所需的最短时间。

输入格式

The first line of the input contains two integers, n and a (1 ≤ a ≤ n ≤ 100 000) — 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.

输入的第一行包含两个整数 nn 和 aa(1 ≤ a ≤ n ≤ 100 0001 ≤ a ≤ n ≤ 100\,000),分别表示街道上的房屋总数以及瓦西亚需要到达的房屋编号。保证 nn 为偶数。

输出格式

Print a single integer — the minimum time Vasya needs to get from the beginning of the street to house a.

输出一个整数——Vasya 从街道起点到达房屋 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.

在第一个样例中,街道上仅有四栋房屋,每侧各两栋。房屋 2 将位于瓦夏右侧的最后一栋。

第二个样例对应于 $ n = 8 $ 的图示。房屋 5 位于瓦夏左侧倒数第二栋。

输入解题思路,AI测评打分。不知道怎么写?

首页