首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【CodeForces】638A - Home Numbers(水)

【CodeForces】638A - Home Numbers(水)

作者头像
FishWang
发布2025-08-26 15:47:57
发布2025-08-26 15:47:57
5900
代码可运行
举报
运行总次数:0
代码可运行

题目链接:点击打开题目

A. Home Numbers

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

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.

Examples

input

代码语言:javascript
代码运行次数:0
运行
复制
4 2

output

代码语言:javascript
代码运行次数:0
运行
复制
2

input

代码语言:javascript
代码运行次数:0
运行
复制
8 5

output

代码语言:javascript
代码运行次数:0
运行
复制
3

Note

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.

题意:给你一个n,奇数在上面递增,偶数在下面递减。再给你一个a,问到a需要多少秒,每走一个房子需要1秒。

代码如下:

代码语言:javascript
代码运行次数:0
运行
复制
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
	int n,a;
	int ans;
	scanf ("%d %d",&n,&a);
	if (a & 1)
		printf ("%d\n",(a+1)>>1);
	else
		printf ("%d\n",((n-a)>>1)+1);
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档