zoukankan      html  css  js  c++  java
  • CF 279A. Point on Spiral

    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
    ");
                continue;
            }
            int maxx = max(abs(x),abs(y));
            int cnt = (maxx-1)*4;
            if((x == maxx||x == maxx-1) && y == 1-maxx)
                printf("%d
    ",cnt);
            else if(x == maxx && y >= 1-maxx && y <= maxx)
                printf("%d
    ",cnt+1);
            else if(x >= -maxx && x <= maxx && y == maxx)
                printf("%d
    ",cnt+2);
            else if(x == -maxx && y >= -maxx && y <= maxx)
                printf("%d
    ",cnt+3);
            else if(x >= -maxx && x <= maxx && y == -maxx)
                printf("%d
    ",cnt+4);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    86. Partition List
    2. Add Two Numbers
    55. Jump Game
    70. Climbing Stairs
    53. Maximum Subarray
    64. Minimum Path Sum
    122. Best Time to Buy and Sell Stock II
    以场景为中心的产品设计方法
    那些产品经理犯过最大的错
    Axure教程:如何使用动态面板?动态面板功能详解
  • 原文地址:https://www.cnblogs.com/luyingfeng/p/3462123.html
Copyright © 2011-2022 走看看