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
  • 相关阅读:
    安卓自动化测试添加用例执行回放
    【十二省2019】异或粽子
    【BZOJ4260】Codechef REBXOR
    【JSOI2015】字符串树
    【HAOI2017】供给侧改革
    【NOI2018】你的名字
    【十二省2019】字符串问题
    【LOJ#6041】事情的相似度
    【SP8093】JZPGYZ
    【BZOJ1396】识别子串
  • 原文地址:https://www.cnblogs.com/luyingfeng/p/3462123.html
Copyright © 2011-2022 走看看