P1228 地毯填补问题

// Problem: P1228 地毯填补问题
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1228
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// User: Pannnn

#include <bits/stdc++.h>

using namespace std;

template<class T>
void debugVector(const T &a) {
    cout << "[ ";
    for (size_t i = 0; i < a.size(); ++i) {
        cout << a[i] << (i == a.size() - 1 ? " " : ", ");
    }
    cout << "]" << endl;
}

template<class T>
void debugMatrix2(const T &a) {
    for (size_t i = 0; i < a.size(); ++i) {
        debugVector(a[i]);
    }
}

template<class T>
using matrix2 = vector<vector<T>>;

template<class T>
vector<vector<T>> getMatrix2(size_t n, size_t m, T init = T()) {
    return vector<vector<T>>(n, vector<T>(m, init));
}

template<class T>
using matrix3 = vector<vector<vector<T>>>;

template<class T>
vector<vector<vector<T>>> getMatrix3(size_t x, size_t y, size_t z, T init = T()) {
    return vector<vector<vector<T>>>(x, vector<vector<T>>(y, vector<T>(z, init)));
}

vector<int> genBigInteger(string a) {
    vector<int> res;
    for (int i = a.size() - 1; i >= 0; --i) {
        res.push_back(a[i] - '0');
    }
    return res;
}

void printBigInteger(vector<int> a) {
    for (size_t i = a.size() - 1; i >= 0; --i) {
        cout << a[i];
    }
}

vector<int> addBigInteger(vector<int> a, vector<int> b) {
    vector<int> res;
    int pre = 0;
    for (size_t i = 0; i < a.size() || i < b.size() || pre; ++i) {
        if (i < a.size()) pre += a[i];
        if (i < b.size()) pre += b[i];
        res.push_back(pre % 10);
        pre /= 10;
    }
    return res;
}

/*
    对于2 * 2的迷宫,障碍物固定后,仅有一种填补地毯的可能 -- 对于2 * 2且有1个障碍物的迷宫的情况。
    对于4 * 4的迷宫,可以将其划分为4块2 * 2的迷宫,其中某一块已经有障碍物,
    我们已经知道2 * 2且有一个障碍物的迷宫的摆放方式,所以只需在正中间放入一块地毯,就可以使得所有2 * 2的方块都有一个障碍
    ....
*/

void divide(int n, int x, int y, int zx, int zy) {
    vector<pair<int, int>> tmpXY = {{zx, zy}, {zx, zy + 1}, {zx + 1, zy}, {zx + 1, zy + 1}};
    vector<pair<int, int>> tmpzXY = {{zx - n / 2, zy - n / 2}, {zx - n / 2, zy + n / 2}, 
                                     {zx + n / 2, zy - n / 2}, {zx + n / 2, zy + n / 2}};
    if (x <= zx && y <= zy) {
        cout << zx + 1 << " " << zy + 1 << " " << 1 << endl;
        tmpXY[0].first = x;
        tmpXY[0].second = y;
    } else if (x <= zx && y > zy) {
        cout << zx + 1 << " " << zy << " " << 2 << endl; 
        tmpXY[1].first = x;
        tmpXY[1].second = y;
    } else if (x > zx && y <= zy) {
        cout << zx << " " << zy + 1 << " " << 3 << endl;
        tmpXY[2].first = x;
        tmpXY[2].second = y;
    } else {
        cout << zx << " " << zy << " " << 4 << endl;
        tmpXY[3].first = x;
        tmpXY[3].second = y;
    }
    if (n == 1) {
        return;
    }
    divide(n / 2, tmpXY[0].first, tmpXY[0].second, tmpzXY[0].first, tmpzXY[0].second);
    divide(n / 2, tmpXY[1].first, tmpXY[1].second, tmpzXY[1].first, tmpzXY[1].second);
    divide(n / 2, tmpXY[2].first, tmpXY[2].second, tmpzXY[2].first, tmpzXY[2].second);
    divide(n / 2, tmpXY[3].first, tmpXY[3].second, tmpzXY[3].first, tmpzXY[3].second);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int k, x, y;
    cin >> k >> x >> y;
    
    divide(pow(2, k - 1), x, y, pow(2, k - 1), pow(2, k - 1));
    return 0;
}
posted @ 2022-03-04 17:35  Pannnn  阅读(90)  评论(0)    收藏  举报
-->