CF 开车找房子
来源:互联网 发布:石膏板隔音墙数据 编辑:程序博客网 时间:2024/05/17 02:57
暑期练习题
Themain street of Berland is a straight line with n housesbuilt along it (n is an evennumber). The houses are located at both sides of the street. The houses withodd numbers are at one side of the street and are numbered from 1 to n - 1 inthe order from the beginning of the street to the end (in the picture: fromleft to right). The houses with even numbers are at the other side of thestreet and are numbered from 2 ton inthe order from the end of the street to its beginning (in the picture: fromright to left). The corresponding houses with even and odd numbers are strictlyopposite each other, that is, house 1 isopposite house n, house 3 isopposite house n - 2,house 5 is opposite house n - 4andso on.
Vasyaneeds to get to house number a asquickly as possible. He starts driving from the beginning of the street anddrives 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 alsospends exactly one second to drive the distance between two neighbouringhouses. Vasya can park at any side of the road, so the distance between thebeginning of the street at the houses that stand opposite one another should beconsidered the same.
Yourtask is: find the minimum time Vasya needs to reach house a.
Input
Thefirst 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 needsto reach, correspondingly. It is guaranteed that number n iseven.
Output
Printa single integer — the minimum time Vasya needs to get from the beginning ofthe street to house a.
Sample Input
Input
42
Output
2
Input
85
Output
3
题意:就是给你一排数字,上排为奇数从左往右增大,下排为偶数,从左往右减小。问题就是你开个小车找到指定的数字需要经过多少房子。
思路:分奇偶性讨论。
代码:
/*=============================AC情况===============================*//*题目网址: *//*时间: *//*心得: */#include<stdio.h>#include<stdlib.h>#include<string.h>#define G 100int main() {int n,a,ans;while(scanf("%d%d",&n,&a)!=EOF) {if(a%2==0)ans=(n-a)/2+1;elseans=(a+1)/2;printf("%d\n",ans);}return 0;}/*********************************测试数据***********************************************************************************************************/
- CF 开车找房子
- 找房子
- 找房子
- 找房子山西卫视
- 找房子了
- 找房子好困难
- 最近在找房子
- 又又找房子!!!
- 20090614找房子
- 找房子的两天
- 开汽车找房子
- 利用python找房子
- 又开始找房子了
- 实习第一周:找房子
- 找房子的辛酸事
- 又要找房子了
- 人通过中介找房子
- CF找规律
- 工具网站
- java dom4j解析XML读取数据源配置的代码实例
- 解决DataNode Volume Failures故障
- 实例讲解基于 React+Redux 的前端开发流程
- HDOJ/HDU 1984 Mispelling4(删除第n个字符~)
- CF 开车找房子
- (二) E - E && hdoj 无限的路 【规律】
- ardunio and blob二次环境
- redisDB
- RHRL7.0安装RAC11.2.0.4----Error in invoking target 'agent nmhs' of makefile '/u01/app/oracle/product/1
- springmvc重定向后jsp如何获取其中的flashAttribute?
- C语言的指针(进阶篇章之一)
- C#—实验9.6和9.7
- 分类器的评估与选择