玄关
查看原帖
玄关
1539892
BOBzzx楼主2025/8/2 19:29

救救我吧,看了一个小时了,re#8是真不知道错哪了

#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int>>v[11];
char c[4005][4005];
void delate(int x, int y)
{
    if (c[x][y] != 'o')
        return;
    c[x][y] = ' ';
    if (c[x + 1][y - 1] == '\\')
    {
        int i = x+1, j = y-1;
        while (c[i][j] != 'o')
        {
            c[i][j] = ' ';
            i++, j--;
        }
    }
    else if(c[x + 1][y + 1] == '/')
    {
        int i = x + 1, j = y + 1;
        while (c[i][j] != 'o')
        {
            c[i][j] = ' ';
            i++, j++;
        }
    }
    if (x == 0 || y == 0)
        return;
    int l1 = x - 1, r1 = y - 1, l2 = x - 1, r2 = y + 1;
    while (1)
    {
        if (c[l1][r1] == 'o' && c[l2][r2] == 'o')
        {
            delate(l1, r1);
            delate(l2, r2);
            break;
        }
        c[l1][r1] = ' ', c[l2][r2] = ' ';
        l1--, l2--, r1--, r2++;
    }
}
int main()
{
    cin >> n>>m;
    int w = (1 << n - 1)/2 * 6 - 1,p=0,l=0;
    for (int i = 0,j=0; i < (1 << n - 1)/2; i++)
    {
        c[0][j] = 'o', c[0][j + 1] = ' ', c[0][j + 2] = ' ', c[0][j + 3] = ' ', c[0][j + 4] = 'o', c[0][j + 5] = ' ';
        j += 6;
        v[n].push_back({ 0,p }), v[n].push_back({ 0,p + 4 });
        p = p + 6;
    }
    int flag = 0,h=n-1,flag2=0;
    while (h>0)
    {
        for (int i = 0; i < w; i++)
        {
            if ((c[l][i] == 'o' && flag == 0) || c[l][i] == '/')
            {
                c[l + 1][i] = ' ';
                c[l + 1][i + 1] = '/';
                flag = 1; 
            }
            else if ((c[l][i] == 'o' && flag == 1) || c[l][i] == '\\')
            {
                c[l+1][i] = ' ';
                if (c[l+1][i - 1] == '/')
                {
                    c[l+1][i - 1] = 'o';
                    v[h].push_back({ l + 1,i - 1 });
                    flag2 = 1;
                }
                else
                    c[l+1][i - 1] = '\\';
                flag = 0;
            }
            else if(c[l+1][i]!='/'&&c[l+1][i]!='o'&&c[l+1][i]!='\\')
                c[l + 1][i] = ' ';
        }
        if (flag2)
        {
            h--;
            flag2 = 0;
        }
        l++;
    }
    while (m--)
    {
        int x, y;
        cin >> x >> y;
        delate(v[x][y - 1].first, v[x][y - 1].second);
    }
    for (int i = l; i >= 0; i--)
    {
        for (int j = 0; j < w; j++)
            cout << c[i][j];
        cout << endl;
    }
    return 0;
}
2025/8/2 19:29
加载中...