CF 开车找房子

来源:互联网 发布:石膏板隔音墙数据 编辑:程序博客网 时间:2024/05/17 02:57

暑期练习题


Themain street of Berland is a straight line with n housesbuilt along it (n is an evennumber). The houses are located at both sides of the street. The houses withodd numbers are at one side of the street and are numbered from 1 to n - 1 inthe order from the beginning of the street to the end (in the picture: fromleft to right). The houses with even numbers are at the other side of thestreet and are numbered from 2 ton inthe order from the end of the street to its beginning (in the picture: fromright to left). The corresponding houses with even and odd numbers are strictlyopposite each other, that is, house 1 isopposite house n, house 3 isopposite house n - 2,house 5 is opposite house n - 4andso on.


Vasyaneeds to get to house number a asquickly as possible. He starts driving from the beginning of the street anddrives 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 alsospends exactly one second to drive the distance between two neighbouringhouses. Vasya can park at any side of the road, so the distance between thebeginning of the street at the houses that stand opposite one another should beconsidered the same.

Yourtask is: find the minimum time Vasya needs to reach house a.

Input

Thefirst 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 needsto reach, correspondingly. It is guaranteed that number n iseven.

Output

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

Sample Input

Input

42

Output

2

Input

85

Output

3

 

 

题意:就是给你一排数字,上排为奇数从左往右增大,下排为偶数,从左往右减小。问题就是你开个小车找到指定的数字需要经过多少房子。

 

思路:分奇偶性讨论。

 

代码:

 

/*=============================AC情况===============================*//*题目网址:   *//*时间: *//*心得:  */#include<stdio.h>#include<stdlib.h>#include<string.h>#define G 100int main() {int n,a,ans;while(scanf("%d%d",&n,&a)!=EOF) {if(a%2==0)ans=(n-a)/2+1;elseans=(a+1)/2;printf("%d\n",ans);}return 0;}/*********************************测试数据***********************************************************************************************************/

 

0 0
原创粉丝点击