http://codeforces.com/problemset/problem/279/A

题意 :就是给你一个螺旋形的图,然后给你一个点,问从(0,0)点到这个点需要转几次弯,当然,是按着这个螺旋图走的。

思路 :好吧,这个题是需要找一下规律的。。。。。。

CF 279A. Point on Spiral

这个图主要注意的是我标了坐标的那四个点,那是每个螺旋的最右下方的点,然后那些带圆圈的是那个点应该转的次数,在(1,0)点转0次,在(2,-1)点转4次,在(3,-2)点需要转8次。所以,坐标中绝对值最大的减掉1再乘上4,而别的边就好说了,和它同一横坐标的次数相同,同一纵坐标的,次数加1,然后是次数加2,次数加3,次数加4.。。。。。。。。。。。。。

#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <iostream>
using namespace std;

int main()
{
    int x,y;
    while(~scanf("%d %d",&x,&y))
    {
        if(x == 0 && y == 0)
        {
            printf("0\n");
            continue;
        }
        int maxx = max(abs(x),abs(y));
        int cnt = (maxx-1)*4;
        if((x == maxx||x == maxx-1) && y == 1-maxx)
            printf("%d\n",cnt);
        else if(x == maxx && y >= 1-maxx && y <= maxx)
            printf("%d\n",cnt+1);
        else if(x >= -maxx && x <= maxx && y == maxx)
            printf("%d\n",cnt+2);
        else if(x == -maxx && y >= -maxx && y <= maxx)
            printf("%d\n",cnt+3);
        else if(x >= -maxx && x <= maxx && y == -maxx)
            printf("%d\n",cnt+4);
    }
    return 0;
}
View Code

相关文章:

  • 2021-07-10
  • 2021-07-06
  • 2021-12-07
  • 2021-04-20
  • 2021-10-01
  • 2021-09-23
  • 2021-07-16
猜你喜欢
  • 2021-10-27
  • 2022-12-23
  • 2022-01-23
  • 2021-11-12
  • 2022-01-11
  • 2022-02-12
  • 2022-12-23
相关资源
相似解决方案