56分求助

P1228 地毯填补问题

fgcjd @ 2024-03-03 15:39:33

过了1、3、5、6

求助!

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <limits>
#include <iomanip>
#include <string>
using namespace std;
typedef long long ll;
int k, sx, sy;
void w(int x, int y, int t){
    cout << y << " " << x << " " << t << endl;
}
void in(int x, int y, int s, int a, int b){
    if (s <= 1) return ;
    int s2 = s;
    s = s / 2;
    if (x <= a && a < x + s && y <= b && b < y + s){
        w(x + s, y + s, 1);
        in(x, y, s, a, b);
        in(x + s, y, s, x + s, y + s - 1);
        in(x, y + s, s, x + s - 1, y + s);
        in(x + s, y + s, s, x + s, y + s);
    }
    else if (x + s <= a && a < x + s2 && y <= b && b < y + s){
        w(x + s - 1, y + s, 2);
        in(x, y, s, x + s - 1, y + s - 1);
        in(x + s, y, s, a, b);
        in(x, y + s, s, x + s - 1, y + s);
        in(x + s, y + s, s, x + s, y + s);
    }
    else if (x <= a && a < x + s && y + s <= b && b < y + s2){
        w(x + s, y + s - 1, 3);
        in(x, y, s, x + s - 1, y + s - 1);
        in(x + s, y, s, x + s, y + s - 1);
        in(x, y + s, s, a, b);
        in(x + s, y + s, s, x + s, y + s);
    }
    else if (x + s <= a && a < x + s2 && y + s <= b && b < y + s2){
        w(x + s - 1, y + s - 1, 4);
        in(x, y, s, x + s - 1, y + s - 1);
        in(x + s, y, s, x + s, y + s - 1);
        in(x, y + s, s, x + s - 1, y + s);
        in(x + s, y + s, s, a, b);
    }
}
int main(){
    cin >> k >> sx >> sy;
    in(1, 1, pow(2, k), sx, sy);
    return 0;
}

by NazunaZIXI @ 2024-03-11 17:30:50

可以检查一下输入时行列坐标是否与题意相符


by 123huchenghao @ 2024-06-28 20:49:41

#include <bits/stdc++.h>
using namespace std;
int k, x, y;

void cover(int x1, int y1, int x2, int y2, int x, int y)
{
    if(x2 - x1 == 1) 
    { 
        if(x1 == x && y1 == y) cout << x2 << " " << y2 << " " << 1 << endl; 
        else if(x1 == x && y2 == y) cout << x2 << " " << y1 << " " << 2 << endl;
        else if(x2 == x && y1 == y) cout << x1 << " " << y2 << " " << 3 << endl;
        else cout << x1 << " " << y1 << " " << 4 << endl;
return;
    }
    int len = x2 - x1 + 1; 
    int half = len / 2; 
    int xa = x1 + half - 1, ya = y1 + half - 1; 
    int xb = x1 + half - 1, yb = y1 + half;
    int xc = x1 + half, yc = y1 + half - 1; 
    int xd = x1 + half, yd = y1 + half;
    if(x >= x1 && x <= xa && y >= y1 && y <= ya) 
    {
        cover(xa, ya, xd, yd, xa, ya);
        xa = x, ya = y;
    }
    else if(x >= x1 && x <= xb && y >= yb && y <= y2)
    {
        cover(xa, ya, xd, yd, xb, yb);
        xb = x, yb = y;
    }
    else if(x >= xc && x <= x2 && y >= y1 && y <= yc)
    {
        cover(xa, ya, xd, yd, xc, yc);
        xc = x, yc = y;
    }
    else 
    {
        cover(xa, ya, xd, yd, xd, yd);
        xd = x, yd = y;
    }
    cover(x1, y1, x1 + half - 1, y1 + half - 1, xa, ya); 
    cover(x1, y1 + half, x1 + half - 1, y2, xb, yb);  
    cover(x1 + half, y1, x2, y1 + half - 1, xc, yc);  
    cover(x1 + half, y1 + half, x2, y2, xd, yd); 
}
int main()
{
    cin >> k >> x >> y;
    cover(1, 1, 1 << k, 1 << k, x, y);
    return 0;
}

by defien_mian_main @ 2024-06-29 23:04:11

你的问题应该是x, y坐标反了,题目里面行坐标是x,列坐标是y

样例的x,y坐标一样所以看不出来问题,输入一个别的数据比如1,1,2,应该输出2,1,2,但你的程序输出了1,2,3

希望能帮到你


by yunyu2 @ 2024-09-17 13:02:21

@123huchenghao

可以讲一下您的思路吗


|