Description
n个房子如下图放置,问去编号为a的房子最短要走多少米
Input
两个整数n和a表示房子数和要去的房子的编号(1<=a<=n<=1e5)
Output
输出去编号为a的房子最短要走多少米
Sample Input
4 2
Sample Output
2
Solution
水题,去奇数房需走(a+1)/2米,去偶数房需走(n-a)/2+1米
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define maxn 1111
int main()
{
int n,a;
while(~scanf("%d%d",&n,&a))
{
if(a%2)printf("%d\n",(a+1)/2);
else printf("%d\n",(n-a)/2+1);
}
return 0;
}