ural 1224. Spiral dfs
来源:互联网 发布:石家庄网络兼职 编辑:程序博客网 时间:2024/06/07 14:03
1224. Spiral
Time limit: 1.0 second
Memory limit: 64 MB
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 Mrespectively). 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
3 5
4
Problem Source: 2002-2003 ACM Central Region of Russia Quarterfinal Programming Contest, Rybinsk, October 2002
class InputReader(): def nextInt(self): return int(input().strip()) def nextLine(self): return input() def nextString(self): return input().strip() def nextInts(self): ints = [] str = input().strip().split() for s in str: if (s is None) or (len(s) == 0): continue ints.append(int(s)) return ints def nextFloats(self): floats = [] str = input().strip().split() for s in str: if (s is None) or (len(s) == 0): continue floats.append(float(s)) return floatsdef gao(n , m): if n == 0 or m == 0: return -1 if n == 1 : return 0 if m == 1 : return 1 if n == 2 : return 2 if m == 2: return 3 if n == 3: return 4 if m == 3: return 5 k = int(min(n , m)/2)-1 return 4 * k + gao(n - 2*k , m - 2*k)if __name__ == '__main__': reader = InputReader() nums = reader.nextInts() n = nums[0] m = nums[1] print(gao(n , m))
阅读全文
0 0
- ural 1224. Spiral dfs
- ural 1224. Spiral
- URAL 1224. Spiral (规律)
- ural 1033. Labyrinth(dfs)
- ural 1171 DFS+DP
- URAL 1033 Labyrinth(DFS)
- ural 1119. Metro DFS
- ural 1033. Labyrinth dfs
- URAL 1033 Labyrinth (DFS)
- URAL 1242 Werewolf (DFS)
- URAL.1033 Labyrinth (DFS)
- ural 1033. Labyrinth dfs
- Ural 1060. Flip Game dfs
- URAL 1298. Knight(DFS)
- URAL 1298 knight dfs搜索
- URAL 1022 Genealogical Tree (DFS)
- URAL 1005 Stone Pile (DFS)
- URAL 1329 Galactic History (DFS)
- 代码杂项 -- 2017-6-27
- C++中string的Reserve() 和 capacity()
- Cmake生成opencv,opencv_contrib的python接口及改进(原+转)
- Unity 判断某个 路径 或 文件 是否存在
- Object-c基础编程学习笔记-对象初始化
- ural 1224. Spiral dfs
- hive函数regexp_extract提取固定长度的数字信息(正则表达)
- 蒙特卡洛方法
- C#零碎知识
- Android Studio 安装 | 配置 (个人笔记)
- 线段树——洛谷 P1471 方差
- windows下 apache配置rewrite错误解决
- NLP:单词嵌入Word Embeddings
- c++中return的用法