题目链接:Codeforces 638A Home Numbers
题意:一条街道两侧有两排房子,街道起点在最左侧。从左到右两排房间编号分别为1、3、5… 和 n、n-2 … 2。给你一个房子编号,问距离起点的距离。
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#define PI acos(-1.0)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define fi first
#define se second
#define ll o<<1
#define rr o<<1|1
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 2*1e5 + 1;
const int pN = 1e6;// <= 10^7
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
void add(LL &x, LL y) { x += y; x %= MOD; }
int main()
{
int n, a; cin >> n >> a;
int ans;
if(a & 1) {
ans = a / 2 + 1;
}
else {
ans = n / 2 - a / 2 + 1;
}
cout << ans << endl;
return 0;
}