奇偶房间号

原创 2016年06月01日 13:13:11
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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 housea. 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.

Input

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.

Output

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

Sample Input

Input
4 2
Output
2
Input
8 5
Output

3

思路:奇数从小到大,偶数从大到小。

代码:

#include<stdio.h>
int main()
{
int n,a;
while(scanf("%d%d",&n,&a)!=EOF)
{
if(a%2==0)
printf("%d\n",(n-a)/2+1);
else
printf("%d\n",(a+1)/2);
}
return 0;
 } 

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

数据结构&算法实践—【排序|交换排序】奇偶排序

转载请注明出处:http://blog.csdn.net/wklken 回主目录 排序>>交换排序>>奇偶排序 List: 0.概念+伪代码+示例分析 1.奇...
  • wklken
  • wklken
  • 2012-05-17 22:36
  • 2992

奇偶页显示不同内容

  • 2014-08-25 19:14
  • 12KB
  • 下载

JavaScript实战-DOM操作之奇偶变色表格

JavaScript实战-DOM操作之奇偶变色表格 全部代码如下: 效果如下:

verilog奇偶分频

  • 2014-04-02 20:03
  • 708KB
  • 下载

AtCoder Regular Contest 080 E - Young Maids [拓扑序+分治+奇偶rmq]||[分块]

http://arc080.contest.atcoder.jp/tasks/arc080_c 其实细想其本质是一道拓扑序的题,选了当前点,才能选分裂出的三段。#include #define pb...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)