URAL 1224. Spiral (规律)

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;
}
时间: 2024-11-06 11:22:30

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

URAL——DFS找规律——Nudnik Photographer

Description If two people were born one after another with one second difference and one of them is a child, then the other one is a child too. We get by induction that all the people are children. Everyone knows that the mathematical department of t

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

1180. Stone Game Time limit: 1.0 second Memory limit: 64 MB Two Nikifors play a funny game. There is a heap of N stones in front of them. Both Nikifors in turns take some stones from the heap. One may take any number of stones with the only condition

URAL 1295 Crazy Notions 数学 找规律

1295. Crazy Notions Time limit: 0.5 second Memory limit: 64 MB For five days robot-loader JK546L54p has been buried under the thick layer of the Sibelian plutonium slag. The terrible strike of the atmospheric electricity has led to the depressurizati

URAL 2070 Interesting Numbers (找规律)

题意:在[L, R]之间求:x是个素数,因子个数是素数,同时满足两个条件,或者同时不满足两个条件的数的个数. 析:很明显所有的素数,因数都是2,是素数,所以我们只要算不是素数但因子是素数的数目就好,然后用总数减掉就好.打个表,找找规律,你会发现, 这些数除外的数都是素数的素数次方,然后就简单了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include &

URAL 1924 Four Imps (博弈论 + 规律)

1924. Four Imps Time limit: 1.0 second Memory limit: 64 MB The world is in danger. One famous swindler passed away recently (by the way, nobody knows his real name, so let's call him Ostap). Having got to the hell he decided to make a deal with the D

URAL 1295. Crazy Notions(数学啊 &amp; 找规律)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1295 1295. Crazy Notions Time limit: 0.5 second Memory limit: 64 MB For five days robot-loader JK546L54p has been buried under the thick layer of the Sibelian plutonium slag. The terrible strike of th

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

ural 2029 Towers of Hanoi Strike Back 链接:http://acm.timus.ru/problem.aspx?space=1&num=2029 题意:汉诺塔问题,给定一串只有(A, B, C)的字符串(A代表在第一根柱子,B代表在第二根柱子,C代表在第三根柱子),从前往后代表盘子的大小,第 i 个字母代表di i 个盘子在某个柱子上.问移动给定字母状态的盘子最少需要多少步. 思路:首先,从后往前看(最大的盘子),如果不在当前柱子上,那么移动到目标柱子需要 2

ural 1260. Nudnik Photographer 规律dp

点击打开链接 1260. Nudnik Photographer Time limit: 1.0 second Memory limit: 64 MB If two people were born one after another with one second difference and one of them is a child, then the other one is a child too. We get by induction that all the people ar

【找规律】URAL - 2065 - Different Sums

就让0出现得尽可能多嘛--大概感受一下就是这样-- 0 0 ... 0 0 0 0 4 -4 3 -3 2 -2 1 -1 #include<cstdio> using namespace std; int n,m,a[510]; int main() { scanf("%d%d",&n,&m); int now=0; for(int i=n,j=1;i>=1;--i,++j) { if(m==1) a[i]=0; else { now=-now; i