zoukankan      html  css  js  c++  java
  • Hihocoder 1324 希尔伯特曲线

    本周Hihocoder的hiho一下

    记得是2017年蓝桥杯B组的填空题

    Hihocoder 1324


    分治解决,观察每次变换,分成4块,将每块相对坐标都转换成左上角的相对坐标,边界是n为0时结果是1

    #include <stdio.h>
    #include <iostream>
    #include <string.h>
    #include <stdlib.h>
    #include <vector>
    #include <algorithm>
    #include <queue>
    #include <map>
    #include <string>
    #include <math.h>
    using namespace std;
    typedef pair<int,int> P;
    typedef long long LL;
    const int INF = 0x3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-9;
    
    LL solve(int n, int x, int y)
    {
        if(n == 0) return 1;
        LL m = 1 << (n-1);
        if(x <= m && y <= m)
            return solve(n-1, y, x);
        if(x <= m && y > m)
            return 1LL*m*m + solve(n-1, x, y-m);
        if(x > m && y > m)
            return 2LL*m*m + solve(n-1, x-m, y-m);
        if(x > m && y <= m)
            return 3LL*m*m + solve(n-1, m+1-y, 2*m+1-x);
    }
    LL n,x,y;
    int main()
    {
        while(~scanf("%lld%lld%lld", &n,&x,&y))
        printf("%lld
    ", solve(n,x,y));
        return 0;
    }
    
    
    如果有错误,请指出,谢谢
  • 相关阅读:
    路由聚合(路由发布时)
    RIP
    路由选择和静态路由
    传输介质和IP地址
    升级VRP
    文件系统
    命令行基础
    常见的网络设备
    mysql基本的修改表的命令
    mysql的外键知识
  • 原文地址:https://www.cnblogs.com/Alruddy/p/7360451.html
Copyright © 2011-2022 走看看