zoukankan      html  css  js  c++  java
  • VK Cup 2016

    A. Home Numbers

    题目连接:

    http://www.codeforces.com/contest/638/problem/A

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

    Sample Input

    4 2

    Sample Output

    2

    Hint

    题意

    有n个房子,现在左边是 1 3 5 7 9 这样的

    右边是 n n-2 n-4 n-6 ... 2这样的

    然后问你x房子离起点的距离是多少

    题解:

    水题……

    分奇数偶数乱看一下就好了……

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    int main()
    {
        int n,x;
        cin>>n>>x;
        if(x%2==1)
            cout<<x/2+1<<endl;
        else
            cout<<(n+2-x)/2<<endl;
    }
  • 相关阅读:
    background-size属性的几个实用的值
    用jQuery实现旋转木马效果(带前后按钮和索引按钮)
    用jQuery制作仿网易云课堂导航菜单效果
    IE8专用hack
    jQuery的slicebox插件实现3D翻转轮播效果
    未知宽高的图片水平垂直居中的几种方法
    清除浮动的几种方法
    用canvas实现鼠标拖动绘制矩形框
    个人收藏的移动端网页布局rem解决方案
    jQuery仿3D旋转木马效果插件(带索引按钮)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5317257.html
Copyright © 2011-2022 走看看