zoukankan      html  css  js  c++  java
  • P1228 地毯填补问题

    #include<iostream>
    #include<vector>
    
    using namespace std;
    
    typedef struct{
        int x, y, c;
    }Node;
    
    vector<Node> res;
    
    void dfs(int k, int x, int y, int dx, int dy){
        if(k == 0) return;
        
        int mx = 1 << k - 1, my = 1 << k - 1;
        if(x > mx && y > my){
            res.push_back({mx + dx, my + dy, 4});
            dfs(k - 1, mx, my, dx, dy);
            dfs(k - 1, mx, 1, dx, my + dy);
            dfs(k - 1, 1, my, mx + dx, dy);
            dfs(k - 1, x - mx, y - my, mx + dx, my + dy);
        }
        if(x > mx && y <= my){
            res.push_back({mx + dx, my + 1 + dy, 3});
            dfs(k - 1, mx, my, dx, dy);
            dfs(k - 1, mx, 1, dx, my + dy);
            dfs(k - 1, 1, 1, mx + dx, my + dy);
            dfs(k - 1, x - mx, y, mx + dx, dy);
        }
        if(x <= mx && y > my){
            res.push_back({mx + 1 + dx, my + dy, 2});
            dfs(k - 1, mx, my, dx, dy);
            dfs(k - 1, 1, 1, mx + dx, my + dy);
            dfs(k - 1, 1, my, mx + dx, dy);
            dfs(k - 1, x, y - my, dx, my + dy);
        }
        if(x <= mx && y <= my){
            res.push_back({mx + 1 + dx, my + 1 + dy, 1});
            dfs(k - 1, mx, 1, dx, my + dy);
            dfs(k - 1, 1, 1, mx + dx, my + dy);
            dfs(k - 1, 1, my, mx + dx, dy);
            dfs(k - 1, x, y, dx, dy);
        }
    }
    
    int main(){
        int k, x, y;
        
        cin >> k >> x >> y;
        
        dfs(k, x, y, 0, 0);
        
        for(auto t : res) cout << t.x << ' ' << t.y << ' ' << t.c << endl;
    }
    
  • 相关阅读:
    zzuli---1912---小火山的爱情密码
    zzuli---1907---
    zzuli---1899---985的最大和难题
    zzuli---1898---985的数字难题
    Light oj ---1058---poj---1971---Parallelogram Counting
    UVA---10200
    poj---1064---Cable master
    hdu---5423---Rikka with Tree
    fzu---2128
    Bookshelf 2 01背包
  • 原文地址:https://www.cnblogs.com/tomori/p/13795303.html
Copyright © 2011-2022 走看看