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

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

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

这个图主要注意的是我标了坐标的那四个点,那是每个螺旋的最右下方的点,然后那些带圆圈的是那个点应该转的次数,在(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

 

posted on 2013-12-06 21:09  枫、  阅读(366)  评论(0编辑  收藏  举报