CF 开车找房子
2016-06-02 13:44
295 查看
暑期练习题
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
题意:就是给你一排数字,上排为奇数从左往右增大,下排为偶数,从左往右减小。问题就是你开个小车找到指定的数字需要经过多少房子。
思路:分奇偶性讨论。
代码:
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 100 int main() { int n,a,ans; while(scanf("%d%d",&n,&a)!=EOF) { if(a%2==0) ans=(n-a)/2+1; else ans=(a+1)/2; printf("%d\n",ans); } return 0; } /*********************************测试数据********************************* **************************************************************************/
相关文章推荐
- RHRL7.0安装RAC11.2.0.4----Error in invoking target 'agent nmhs' of makefile '/u01/app/oracle/product/1
- IPv6进阶
- 源码编译php-5 报错整理
- redisDB
- 阿里云ECS—wordpress配置(主题/页脚/流量)
- 双向链表——基本操作
- 史上最全最强SpringMVC详细示例实战教程
- 查看光纤卡wwn号【转载】
- mysql 安全
- java dom4j解析XML读取数据源配置的代码实例
- (Java程序员)简单了解网站搭建的所处流程
- HTTP基础:URL格式、 HTTP请求、响应、消息
- 实例讲解基于 React+Redux 的前端开发流程
- 解决DataNode Volume Failures故障
- web控件
- h5小游戏——HitRocket
- HDOJ/HDU 1984 Mispelling4(删除第n个字符~)
- HDOJ/HDU 1984 Mispelling4(删除第n个字符~)
- 关于模板页调用js的问题
- MongoDB 3.X 用户权限控制