14分求助

P1228 地毯填补问题

imnoob @ 2024-03-02 08:53:48

点2AC, 其他全WA

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
long long k, x, y;
void slove(long long x1, long long y1, long long x2, long long y2, long long n)
{
    if(n == 1)
    {
        return;
    }
    n /= 2;
    if(x1 - x2 < n && y1 - y2 < n)
    {
        cout << x2 + n << ' ' << y2 + n << ' ' << 1 << '\n';
        slove(x1, y1, x2, y2, n);
        slove(x2 + n - 1, y2 + n, x2, y2 + n, n);
        slove(x2 + n, y2 + n - 1, x2 + n, y2, n);
        slove(x2 + n, y2 + n, x2 + n, y2 + n, n);
        return;
    }
    if(x1 - x2 < n && y1 - y2 >= n)
    {
        cout << x2 + n << ' ' << y2 + n - 1 << ' ' << 2 << '\n';
        slove(x2 + n - 1, y2 + n - 1, x2, y2, n);
        slove(x1, y1, x2, y2 + n, n);
        slove(x2 + n, y2 + n - 1, x2 + n, y2, n);
        slove(x2 + n, y2 + n, x2 + n, y2 + n, n);
        return;
    }
    if(x1 - x2 >= n && y1 - y2 < n)
    {
        cout << x2 + n - 1 << ' ' << y2 + n << ' ' << 3 << '\n';
        slove(x2 + n - 1, y2 + n - 1, x2, y2, n);
        slove(x2 + n - 1, y2 + n, x2, y2 + n, n);
        slove(x1, y1, x2 + n, y2, n);
        slove(x2 + n, y2 + n, x2 + n, y2 + n, n);
        return;
    }
    cout << x2 + n - 1 << ' ' << y2 + n - 1 << ' ' << 4 << '\n';
    slove(x2 + n - 1, y2 + n - 1, x2, y2, n);
    slove(x2 + n - 1, y2 + n, x2, y2 + n, n);
    slove(x2 + n, y2 + n - 2, x2 + n, y2, n);
    slove(x1, y1, x2 + n, y2 + n, n);
    return;
}
int main()
{
    cin >> k >> x >> y;
    slove(x, y, 1, 1, pow(2, k));
    return 0;
}

|