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. unlocked_ioctl和compat_ioctl

    参考: https://www.cnblogs.com/super119/archive/2012/12/03/2799967.html https://lwn.net/Articles/119652 ...

  2. 利用mvn deploy命令上传包(转)

    本文转自https://blog.csdn.net/chenaini119/article/details/52764543 mvn安装 下载maven的bin,在apache官方网站可以下载. ht ...

  3. 【python】python读写文件,都不乱码

    读是按照文本的编码方式读取,写是按照文本的编码方式追加 import chardet fileName = 'E:/2/采集数据_pswf12_180大0小35750_20181206.txt' # ...

  4. ibatis.net:第四天,Update 和 Delete

    xml <update id="UpdateOrder" parameterClass="Order"> UPDATE [Orders] SET C ...

  5. docker 容器间网络配置

    创建一个docker容器,docker系统会自动为该容器分配一个ip地址,通常是172.17开头. 我们可以在主机上用 docker inspect 命令 或者进入容器用ifconfig命令来查看容器 ...

  6. 行尸走肉第八季/全集The Walking Dead迅雷下载

    <行尸走肉第八季>将在10月22号回归播出, 将于5月1日起正式开始拍摄!目前剧组已开始招募客串演员和丧尸群演,第八季拍摄时长初步预计会持续到11月16日.而这三位已确认为<行尸走肉 ...

  7. 女子监狱第四季/全集Orange Is the New Black迅雷下载

    女子监狱 第三季 Orange Is the New Black 3 (2015) 本季看点:该剧由<吉尔莫女孩>.<单身毒妈第一季>编剧杰姬·科恩的打造.由<护士当家& ...

  8. [Hook] 免root,自己进程内,startActivity hook的几种姿势

    首先关于startActivity 我们平时会经常使用到 在activity内 直接startActivity(intent) 其实这里还有一种start方式 我们可能没怎么用过 getApplica ...

  9. Forward secrecy

    In cryptography, forward secrecy (FS), also known as perfect forward secrecy (PFS), is a property of ...

  10. [转]mysql在已有无分区表增加分区,mysql5.5才有,可以是innodb_file_per_table关闭状态.

    FROM : http://blog.csdn.net/sunvince/article/details/7752662 mysql5.1的时候新增的partition,解决了比较简单的shardin ...