URAL 1224. Spiral (Regular)

Source: Internet
Author: User

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
input Output
3 5
4
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.