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

Problem Source: 2002-2003 ACM Central Region of Russia Quarterfinal Programming Contest, Rybinsk, October 2002

解析:找规律。一定要注意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;
}

URAL 1224. Spiral (规律)的更多相关文章

  1. 【规律】Growing Rectangular Spiral

    Growing Rectangular Spiral 题目描述 A growing rectangular spiral is a connected sequence of straightline ...

  2. URAL 2070 Interesting Numbers (找规律)

    题意:在[L, R]之间求:x是个素数,因子个数是素数,同时满足两个条件,或者同时不满足两个条件的数的个数. 析:很明显所有的素数,因数都是2,是素数,所以我们只要算不是素数但因子是素数的数目就好,然 ...

  3. URAL 1780 G - Gray Code 找规律

    G - Gray CodeTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...

  4. URAL 1180. Stone Game (博弈 + 规律)

    1180. Stone Game Time limit: 1.0 second Memory limit: 64 MB Two Nikifors play a funny game. There is ...

  5. Ural 2045. Richness of words 打表找规律

    2045. Richness of words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2045 Description For ...

  6. Ural 2037. Richness of binary words 打表找规律 构造

    2037. Richness of binary words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2037 Descripti ...

  7. ural 2029 Towers of Hanoi Strike Back (数学找规律)

    ural 2029 Towers of Hanoi Strike Back 链接:http://acm.timus.ru/problem.aspx?space=1&num=2029 题意:汉诺 ...

  8. URAL 2037 Richness of binary words (回文子串,找规律)

    Richness of binary words 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/B Description Fo ...

  9. URAL 2065 Different Sums (找规律)

    题意:构造一个数列,使得它们的区间和的种类最少,其中数列中不同的数的数目不少于k. 析:我们考虑0这个特殊的数字,然后0越多,那么总和种类最少,再就是正负交替,那么增加0的数量. 代码如下: #pra ...

随机推荐

  1. 委托, 泛型委托,Func<T>和Action<T>

    使用委托来做一些事情,大致思路是: 1.定义声明一个委托,规定输入参数和输出类型.2.写几个符合委托定义的方法.3.把方法列表赋值给委托4.执行委托 internal delegate int MyD ...

  2. C#编程(七十)----------dynamic类型

    原文链接 : http://blog.csdn.net/shanyongxu/article/details/47296033 dynamic类型 C#新增了dynamic关键字,正是因为这一个小小的 ...

  3. C# String.split()用法小结

    第一种方法 string s=abcdeabcdeabcde; string[] sArray=s.Split('c') ; foreach(string i in sArray) Console.W ...

  4. WordPress主题开发:网站搜索

    调用方法一:手动输入html <form role="search" method="get" id="searchform" act ...

  5. SharePoint PowerShell 修改计时器任务

    前言 最近碰到需要修改计时器任务的需求,然后搜了搜,发现有powershell命令可以搞定,记录一下. $timerJob = Get-SPTimerJob -Identity "DocID ...

  6. left join 注意事项

    相信对于熟悉SQL的人来说,LEFT JOIN非常简单,采用的时候也很多,但是有个问题还是需要注意一下.假如一个主表M有多个从表的话A B C …..的话,并且每个表都有筛选条件,那么把筛选条件放到哪 ...

  7. 超感猎杀/超感八人组第一季至二季/全集Sense8迅雷下载

    本季 Sense8 (2015)看点:<超感八人组>由沃卓斯基姐弟执导的科幻剧集是Netflix继“纸牌屋第二季”后的又一大手笔制作,讲述未来世界不同地区的8个人因同时目睹同一暴力事件.从 ...

  8. 关于chrome插件编写的小结

    一个插件的大致目录结构如下: 其中manifest文件最为重要,它定义/指明插件应用的相关信息(权限.版本.功能说明等),点此查看Manifest的详情>>   这里有一篇chrome官方 ...

  9. LeakCanary,30分钟从入门到精通

    简述 在性能优化中,内存是一个不得不聊的话题:然而内存泄漏,显示已经成为内存优化的一个重量级的方向.当前流行的内存泄漏分析工具中,不得不提的就是LeakCanary框架:这是一个集成方便, 使用便捷, ...

  10. 限制EditText必须输入中文的方法

    给EditText做限制时,我们想要输入的字符串必须都是中文,不出现任何其他字符,下面的类可以很好的实现这个要求. InputLenLimit.java package com.kale.button ...