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 has an integer height and width (
Nand
Mrespectively). Before the robot begins its work it's placed near the top leftmost cell of the rectangle heading right. Then the robot starts moving and neutralizing mines making a clockwise spiral the. The spiral twists towards the inside of the region, and covering all the cells. The region was considered safe when all the cells were visited and checked by the robot. Your task is to determine the number of the turns the robot have to make during it work. Inputthe input contains, integers in the following order:
N,
M (1≤
N,
M ≤231? 1) . Outputthe output consists of a single integer value-the number of the turns. Sample
problem Source:2002-2003 ACM Central Region of Russia quarterfinal programming Contest, Rybinsk, October 2002
Analysis: Find the law. Be sure to pay attention to the size relationship of N and M, as the departure point is fixed.
AC Code:
#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;}
URAL 1224. Spiral (Regular)