URAL 1224. Spiral (规律)
2015-06-07 11:42
330 查看
1224. Spiral
Time limit: 1.0 second
Memory limit: 64 MB
A brand new sapper robot is able to neutralize mines in a rectangular region having integer height and width (N and
M respectively). Before the robot begins its work it is placed near the top leftmost cell of the rectangle heading right. Then the robot starts moving and neutralizing mines making a clockwise spiral way (see picture). The spiral twists towards the
inside of the region, covering all the cells. The region is considered safe when all the cells are visited and checked by the robot.
Your task is to determine the number of the turns the robot has to make during its work.
Input
The input contains two integers in the following order:N, M (1 ≤ N, M ≤ 231 − 1).
Output
The output consists of a single integer value — the number of the turns.Sample
input | output |
---|---|
3 5 | 4 |
解析:找规律。一定要注意n和m的大小关系,因为出发地点是固定的。
AC代码:
#include <bits/stdc++.h> using namespace std; int main(){ long long n, m; while(~scanf("%lld%lld", &n, &m)){ long long ans; if(n <= m) ans = 2 * (n - 1); else ans = 2 * m - 1; printf("%lld\n", ans); } return 0; }
相关文章推荐
- ThinkPHP隐藏index.php出现No input file specified的解决方法
- 【leetcode】Count Primes
- [镜像制作]VMWare搭建Openstack——Ubuntu怎么制作最小的镜像文件(二)
- [leetcode] Remove Element
- 动态存储管理
- 练习作品7:批量做字库 识别码
- Ubuntu14.04,64位操作系统安装部分android32位lib不兼容问题
- 读刘未鹏老师的《怎样花两年时间去面试一个人》有感
- Ubuntu安装apache+php+mysql
- Tiny4412-LED小灯裸机程序
- javascript标签位置以及defer、async属性的区别
- error C2512: “Rectangle”: 没有合适的默认构造函数可用
- [镜像制作]VMWare搭建Openstack——Ubuntu怎么制作最小的镜像文件(一)
- css选择器
- "lianren"项目解析(一)
- 9.线性回归
- oracle异常
- Java异常
- 安卓Android控件ListView嵌套EditText控件
- 分享一些OpenCV实现立体视觉的经验