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;
    }
    
    
    如果有错误,请指出,谢谢
  • 相关阅读:
    Using the @synchronized Directive
    What Are Threads?
    ios 线程同步
    CAAnimation 动画支撑系统
    UIView 动画 依赖与 CALayer的证据
    动画的定义
    Core Animation1-简介
    繁的是表象,简的是本质
    完全自定义动画
    线程安全与可重入
  • 原文地址:https://www.cnblogs.com/Alruddy/p/7360451.html
Copyright © 2011-2022 走看看