题解:P3693 琪露诺的冰雪小屋

· · 题解

一道我感觉还好的大模拟,但是细节挺多的。

接下来,我们来一步步拆解这个大模拟。

基本框架

:::success[code]

#include<bits/stdc++.h>
using namespace std;
int n,h_limit,house_x,house_y,house_length,house_width,t;
string query;
int main()
{
    cin >> n >> h_limit >> house_x >> house_y >> house_length >> house_width >> t;
    while(t--)
    {
        cin >> query;
        //代码
    }
    return 0;
}

:::

我相信这一部分我无需多说。

操作 1—— 冰雪弹幕

首先注意到,这个有着 8 个方向,所以不太好遍历,这时我们可以考虑这样:

x_axis = ((q3 + 2) % 4 == 0?0:(q3 == 0 || q3 == 1 || q3 == 7?-1:1));
y_axis = (q3 % 4 == 0?0:(q3 < 4?-1:1));

看不懂?那加上这个呢:

while(/*边界条件*/)
{
    //干些什么……
    bx += x_axis;
    by += y_axis;
}

这里的 x_axis 和 y_axis 表示两个方向上每一步该怎么移动。

那这一点解决了这一部分的代码也就清晰了:

:::success[code]

    while(t--)
    {
        cin >> query;
        if(query == "ICE_BARRAGE")
        {
            cin >> q1 >> q2 >> q3 >> q4;
            x_axis = ((q3 + 2) % 4 == 0?0:(q3 == 0 || q3 == 1 || q3 == 7?-1:1));
            y_axis = (q3 % 4 == 0?0:(q3 < 4?-1:1));
            bx = q1;
            by = q2;
            freeze_cnt = 0;
            steps = 0;
            while(bx >= 0 && bx < n && by >= 0 && by < n && steps <= q4)
            {
                steps++;
                if(ice[bx][by][0])
                {
                    break;
                }
                else if(frozen[bx][by] < 4)
                {
                    frozen[bx][by]++;
                    freeze_cnt++;
                }
                bx += x_axis;
                by += y_axis;
            }
            cout << "CIRNO FREEZED " << freeze_cnt << " BLOCK(S)\n";
        }
    }
/*
变量解释:
(int)frozen存地面位置的冷冻度。
(bool)ice存每个地方有没有冰块。
(int)bx,(int)by表示目前弹幕的坐标。
(int)steps表示弹幕到第几步了。
*/

:::

也就是实时模拟弹幕的位置,出边界 / 遇到方块就停下来,然后如果成功冷冻度 + 1 就把冻结数加一下。没了。

操作 2—— 收集冰块

更简单了,遍历一遍 frozen 即可。

:::success[code]

        else if(query == "MAKE_ICE_BLOCK")
        {
            this_round_ice_block_cnt = 0;
            for(int i = 0;i < n;i++)
            {
                for(int j = 0;j < n;j++)
                {
                    if(frozen[i][j] == 4)
                    {
                        frozen[i][j] = 0;
                        ice_block_cnt++;
                        this_round_ice_block_cnt++;
                    }
                }
            }
            cout << "CIRNO MADE " << this_round_ice_block_cnt << " ICE BLOCK(S),NOW SHE HAS " << ice_block_cnt << " ICE BLOCK(S)\n";
        }

:::

无需多说。

操作 3—— 放置冰块

依旧简单,如果 ice[x][y][z](这里 x, y, z 表示输入坐标)为真或者在空中并且周围六个方块都没有,那就骂一下琪露诺,否则按照题目给的公式看一下放哪里了即可。

::::success[code]

        else if(query == "PUT_ICE_BLOCK")
        {
            cin >> q1 >> q2 >> q3;
            if(!ice_block_cnt)
            {
                cout << "CIRNO HAS NO ICE_BLOCK\n";
                continue;
            }
            else if(no_blocks_around(q1,q2,q3) || ice[q1][q2][q3])
            {
                cout << "BAKA CIRNO,CAN'T PUT HERE\n";
                continue;
            }
            else if(q1 < house_x || q1 > house_x + house_length - 1 || q2 < house_y || q2 > house_y + house_width - 1)
            {
                cout << "CIRNO MISSED THE PLACE\n";
            }
            else if(house_x < q1 && q1 < house_x + house_length - 1 && house_y < q2 && q2 < house_y + house_width - 1)
            {
                cout << "CIRNO PUT AN ICE_BLOCK INSIDE THE HOUSE\n";
            }
            else
            {
                cout << "CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS " << ice_block_cnt - 1 << " ICE_BLOCK(S)\n";
            }
            ice_block_cnt--;
            ice[q1][q2][q3] = 1;
            if(!q3)
            {
                frozen[q1][q2] = 0;
            }
        }

:::info[其中函数 no_blocks_around]

bool no_blocks_around(int x,int y,int z)
{
    return (z && (!in_range(x - 1,y,z) || !ice[x - 1][y][z]) && (!in_range(x + 1,y,z) || !ice[x + 1][y][z]) && (!in_range(x,y - 1,z) || !ice[x][y - 1][z]) && (!in_range(x,y + 1,z) || !ice[x][y + 1][z]) && (!in_range(x,y,z - 1) || !ice[x][y][z - 1]) && (!in_range(x,y,z + 1) || !ice[x][y][z + 1]));
}
:::

还是代码无需多言。

操作 4—— 移除冰块

还是十分简单。

移除后,写一个最简单的三维 BFS 跑一下找连通块就行。如果连通块没有地方碰到了地,就清空。

:::::success[code]

        else if(query == "REMOVE_ICE_BLOCK")
        {
            cin >> q1 >> q2 >> q3;
            if(!ice[q1][q2][q3])
            {
                cout << "BAKA CIRNO,THERE IS NO ICE_BLOCK\n";
            }
            else
            {
                remove_block(q1,q2,q3);
                cout << "CIRNO REMOVED AN ICE_BLOCK";
                if(broken_cnt)
                {
                    cout << ",AND " << broken_cnt << " BLOCK(S) ARE BROKEN";
                }
                cout << "\n";
            }
        }

::::info[其中 remove_block 函数]

void remove_block(int q1,int q2,int q3)
{
    ice[q1][q2][q3] = 0;
    ice_block_cnt++;
    broken_cnt = 0;
    memset(vis,0,sizeof(vis));
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < n;j++)
        {
            for(int l = 0;l <= h_limit;l++)
            {
                if(ice[i][j][l] && !vis[i][j][l])
                {
                    broken_cnt += bfs(i,j,l);
                }
            }
        }
    }
}

:::info[其中 bfs 函数]

int bfs(int x,int y,int z)
{
    while(!bfs_x.empty())
    {
        bfs_x.pop();
    }
    while(!bfs_y.empty())
    {
        bfs_y.pop();
    }
    while(!bfs_z.empty())
    {
        bfs_z.pop();
    }
    memset(pvis,0,sizeof(pvis));
    bfs_x.push(x);
    bfs_y.push(y);
    bfs_z.push(z);
    this_part[0].clear();
    this_part[1].clear();
    this_part[2].clear();
    int fx,fy,fz,bk = 0;
    bool in_air = 1;
    while(!bfs_x.empty())
    {
        fx = bfs_x.front();
        fy = bfs_y.front();
        fz = bfs_z.front();
        if(in_range(fx,fy,fz) && ice[fx][fy][fz] && !pvis[fx][fy][fz])
        {
            this_part[0].push_back(fx);
            this_part[1].push_back(fy);
            this_part[2].push_back(fz);
            vis[fx][fy][fz] = 1;
            pvis[fx][fy][fz] = 1;
            bfs_x.push(fx - 1);bfs_y.push(fy);bfs_z.push(fz);
            bfs_x.push(fx + 1);bfs_y.push(fy);bfs_z.push(fz);
            bfs_x.push(fx);bfs_y.push(fy - 1);bfs_z.push(fz);
            bfs_x.push(fx);bfs_y.push(fy + 1);bfs_z.push(fz);
            bfs_x.push(fx);bfs_y.push(fy);bfs_z.push(fz - 1);
            bfs_x.push(fx);bfs_y.push(fy);bfs_z.push(fz + 1);
            if(!fz)
            {
                in_air = 0;
            }
        }
        bfs_x.pop();
        bfs_y.pop();
        bfs_z.pop();
    }
    if(in_air)
    {
        for(int i = 0;i < this_part[0].size();i++)
        {
            ice[this_part[0][i]][this_part[1][i]][this_part[2][i]] = 0;
            bk++;
        }
    }
    return bk;
}
:::
:::::

又双叒叕无需多言。

操作 5—— 做房顶

说实话我这次真不能说容易了。

Part1—— 做房顶

遍历一下子墙的最高点然后暴力出奇迹造屋顶即可。

::::success[code]

            roof_h = highest_wall() + 1;
            for(int i = house_x;i < house_x + house_length;i++)
            {
                for(int j = house_y;j < house_y + house_width;j++)
                {
                    if(!ice[i][j][roof_h])
                    {
                        roof_block_cnt++;
                        ice[i][j][roof_h] = 1;
                    }
                }
            }
            ice_block_cnt -= roof_block_cnt;
            if(ice_block_cnt < roof_block_cnt)
            {
                cout << "SORRY CIRNO,NOT ENOUGH ICE_BLOCK(S) TO MAKE ROOF";
                break;
            }

:::info[其中 highest_wall 函数]

int highest_wall()
{
    int mx = -1;
    for(int i = house_x;i < house_x + house_length;i++)
    {
        for(int j = house_y;j < house_y + house_width;j++)
        {
            if((i == house_x || i == house_x + house_length - 1) || (j == house_y || j == house_y + house_width - 1))
            {
                for(int k = h_limit;k >= 0;k--)
                {
                    if(ice[i][j][k])
                    {
                        mx = max(mx,k);
                        break;
                    }
                }
            }
        }
    }
    return mx;
}
:::

Part2—— 判断房子大小

简单。按照给的公式即可。

:::success[code]

            else if(roof_h < 2 || (house_length - 2) * (house_width - 2) * roof_h < 2)
            {
                cout << "SORRY CIRNO,HOUSE IS TOO SMALL";
                break;
            }

:::

Part3—— 多余方块

暴力出奇迹!!!

注意的是,由于遍历顺序原因,所以去除方块得用最基本的去除(不考虑重力)。

:::success[code]

            for(int i = 0;i < n;i++)
            {
                for(int j = 0;j < n;j++)
                {
                    for(int l = 0;l <= h_limit;l++)
                    {
                        if((i < house_x || i > house_x + house_length - 1 || j < house_y || j > house_y + house_width - 1 || l > roof_h) && ice[i][j][l])
                        {
                            out_ice_cnt++;
                            ice[i][j][l] = 0;
                            ice_block_cnt++;
                        }
                        else if(house_x < i && i < house_x + house_length - 1 && house_y < j && j < house_y + house_width - 1 && l < roof_h && ice[i][j][l])
                        {
                            in_ice_cnt++;
                            ice[i][j][l] = 0;
                            ice_block_cnt++;
                        }
                    }
                }
            }
            cout << in_ice_cnt << " ICE_BLOCK(S) INSIDE THE HOUSE NEED TO BE REMOVED\n" << out_ice_cnt << " ICE_BLOCK(S) OUTSIDE THE HOUSE NEED TO BE REMOVED\n";

:::

Part4—— 房子塌没塌

遍历屋顶 BFS 一下即可。

:::success[code]

            broken_cnt = 0;
            memset(vis,0,sizeof(vis));
            for(int i = house_x;i < house_x + house_length;i++)
            {
                for(int j = house_y;j < house_y + house_width;j++)
                {
                    if(ice[i][j][roof_h] && !vis[i][j][roof_h])
                    {
                        broken_cnt += bfs(i,j,roof_h);
                    }
                }
            }
            if(broken_cnt)
            {
                cout << "SORRY CIRNO,HOUSE IS BROKEN WHEN REMOVING BLOCKS";
                break;
            }

:::

Part5—— 墙缺口的计算

依旧暴力出奇迹。

:::success[code]

            for(int i = house_x;i < house_x + house_length;i++)
            {
                for(int j = house_y;j < house_y + house_width;j++)
                {
                    if(((i == house_x || i == house_x + house_length - 1) || (j == house_y || j == house_y + house_width - 1)) && !((i == house_x || i == house_x + house_length - 1) && (j == house_y || j == house_y + house_width - 1)))
                    {
                        for(int l = 0;l < roof_h;l++)
                        {
                            if(!ice[i][j][l])
                            {
                                wall_cnt++;
                            }
                        }
                    }
                }
            }

:::

Part6—— 门

这就比较复杂了。

我们可以用一个评分系统,位置确定后修好墙剩余方块的权值 > 门大小 > 在不在中间。

注意门开在角落的话挨着门的柱子算作是墙。

:::success[code]

            for(int i = house_x;i < house_x + house_length;i++)
            {
                for(int j = house_y;j < house_y + house_width;j++)
                {
                    if(((i == house_x || i == house_x + house_length - 1) || (j == house_y || j == house_y + house_width - 1)) && !((i == house_x || i == house_x + house_length - 1) && (j == house_y || j == house_y + house_width - 1)))
                    {
                        door_score = wall_cnt - (!ice[i][j][0]?1:0) - (!ice[i][j][1]?1:0);
                        if(i == house_x + 1 || i == house_x + house_length - 2 || j == house_y + 1 || j == house_y + house_width - 2)
                        {
                            if(i == house_x + 1)
                            {
                                door_score += (!ice[i][j][0] && !ice[i - 1][j][0]?1:0) + (!ice[i][j][1] && !ice[i - 1][j][1]?1:0);
                                help_corner_cnt += (!ice[i][j][0] && !ice[i - 1][j][0]?1:0) + (!ice[i][j][1] && !ice[i - 1][j][1]?1:0);
                            }
                            if(i == house_x + house_length - 2)
                            {
                                door_score += (!ice[i][j][0] && !ice[i + 1][j][0]?1:0) + (!ice[i][j][1] && !ice[i + 1][j][1]?1:0);
                                help_corner_cnt += (!ice[i][j][0] && !ice[i + 1][j][0]?1:0) + (!ice[i][j][1] && !ice[i + 1][j][1]?1:0);
                            }
                            if(j == house_y + 1)
                            {
                                door_score += (!ice[i][j][0] && !ice[i][j - 1][0]?1:0) + (!ice[i][j][1] && !ice[i][j - 1][1]?1:0);
                                help_corner_cnt += (!ice[i][j][0] && !ice[i][j - 1][0]?1:0) + (!ice[i][j][1] && !ice[i][j - 1][1]?1:0);
                            }
                            if(j == house_y + house_width - 2)
                            {
                                door_score += (!ice[i][j][0] && !ice[i][j + 1][0]?1:0) + (!ice[i][j][1] && !ice[i][j + 1][1]?1:0);
                                help_corner_cnt += (!ice[i][j][0] && !ice[i][j + 1][0]?1:0) + (!ice[i][j][1] && !ice[i][j + 1][1]?1:0);
                            }
                        }
                        door_score = 1200 - door_score + help_corner_cnt;
                        door_score *= 10;
                        door_score += (!ice[i][j][0] && !ice[i][j][1]?1:0);
                        door_score *= 10;
                        door_score += ((house_length % 2 && i == house_x + house_length / 2 || house_length % 2 == 0 && i == house_x + house_length / 2 || i == house_x + house_length / 2 - 1) || (house_width % 2 && j == house_y + house_width / 2 || house_width % 2 == 0 && j == house_y + house_width / 2 || j == house_y + house_width / 2 - 1)?1:0);
                        if(door_score > mx_door_score)
                        {
                            mx_door_score = door_score;
                            door_x = i;
                            door_y = j;
                        }
                    }
                }
            }

:::

Part7—— 各个评级

算它就完事了。

具体怎么判断请看代码:

:::success[code]

            if(wall_cnt > ice_block_cnt)
            {
                cout << "SORRY CIRNO,NOT ENOUGH ICE_BLOCKS TO FIX THE WALL";
                break;
            }
            ice_block_cnt -= wall_cnt;
            cout << "GOOD JOB CIRNO,SUCCESSFULLY BUILT THE HOUSE\n";
            if(!ice[door_x][door_y][0] && !ice[door_x][door_y][1])
            {
                cout << "DOOR IS OK\n";
            }
            else
            {
                cout << "HOUSE HAS NO DOOR\n";
                perfect = 0;
                ice_block_cnt += (ice[door_x][door_y][0]?1:0) + (ice[door_x][door_y][1]?1:0);
            }
            if(wall_cnt)
            {
                cout << "WALL NEED TO BE FIXED\n";
                perfect = 0;
            }
            else
            {
                cout << "WALL IS OK\n";
            }
            for(int i = house_x;i < house_x + house_length;i++)
            {
                for(int j = house_y;j < house_y + house_width;j++)
                {
                    if((i == house_x || i == house_x + house_length - 1) && (j == house_y || j == house_y + house_width - 1))
                    {
                        for(int l = 0;l < roof_h;l++)
                        {
                            if(!ice[i][j][l])
                            {
                                corner_cnt++;
                            }
                        }
                    }
                }
            }
            if(corner_cnt)
            {
                cout << "CORNER NEED TO BE FIXED\n";
                perfect = 0;
            }
            else
            {
                cout << "CORNER IS OK\n";
            }
            ice_block_cnt = max(ice_block_cnt - corner_cnt,0);
            cout << "CIRNO FINALLY HAS " << ice_block_cnt << " ICE_BLOCK(S)\n";
            if(perfect && ((house_length % 2 && door_x == house_x + house_length / 2 || house_length % 2 == 0 && door_x == house_x + house_length / 2 || door_x == house_x + house_length / 2 - 1) || (house_width % 2 && door_y == house_y + house_width / 2 || house_width % 2 == 0 && door_y == house_y + house_width / 2 || door_y == house_y + house_width / 2 - 1)))
            {
                cout << "CIRNO IS PERFECT!";
            }

:::

至此,代码写完辣!

完整代码

:::success[final code]{open}

#include<bits/stdc++.h>
using namespace std;
int n,h_limit,house_x,house_y,house_length,house_width,t,frozen[32][32],q1,q2,q3,q4,x_axis,y_axis,bx,by,freeze_cnt,ice_block_cnt,this_round_ice_block_cnt,steps,broken_cnt,roof_h,roof_block_cnt,in_ice_cnt,out_ice_cnt,door_x,door_y,mx_door_score = -1,wall_cnt,corner_cnt,perfect,help_corner_cnt;
double door_score;
bool ice[32][32][32],vis[32][32][32],pvis[32][32][32];
vector<int>this_part[3];
string query;
queue<int>bfs_x,bfs_y,bfs_z;
bool in_range(int x,int y,int z)
{
    return (x >= 0 && x < n && y >= 0 && y < n && z >= 0 && z <= h_limit);
}
bool no_blocks_around(int x,int y,int z)
{
    return (z && (!in_range(x - 1,y,z) || !ice[x - 1][y][z]) && (!in_range(x + 1,y,z) || !ice[x + 1][y][z]) && (!in_range(x,y - 1,z) || !ice[x][y - 1][z]) && (!in_range(x,y + 1,z) || !ice[x][y + 1][z]) && (!in_range(x,y,z - 1) || !ice[x][y][z - 1]) && (!in_range(x,y,z + 1) || !ice[x][y][z + 1]));
}
int bfs(int x,int y,int z)
{
    while(!bfs_x.empty())
    {
        bfs_x.pop();
    }
    while(!bfs_y.empty())
    {
        bfs_y.pop();
    }
    while(!bfs_z.empty())
    {
        bfs_z.pop();
    }
    memset(pvis,0,sizeof(pvis));
    bfs_x.push(x);
    bfs_y.push(y);
    bfs_z.push(z);
    this_part[0].clear();
    this_part[1].clear();
    this_part[2].clear();
    int fx,fy,fz,bk = 0;
    bool in_air = 1;
    while(!bfs_x.empty())
    {
        fx = bfs_x.front();
        fy = bfs_y.front();
        fz = bfs_z.front();
        if(in_range(fx,fy,fz) && ice[fx][fy][fz] && !pvis[fx][fy][fz])
        {
            this_part[0].push_back(fx);
            this_part[1].push_back(fy);
            this_part[2].push_back(fz);
            vis[fx][fy][fz] = 1;
            pvis[fx][fy][fz] = 1;
            bfs_x.push(fx - 1);bfs_y.push(fy);bfs_z.push(fz);
            bfs_x.push(fx + 1);bfs_y.push(fy);bfs_z.push(fz);
            bfs_x.push(fx);bfs_y.push(fy - 1);bfs_z.push(fz);
            bfs_x.push(fx);bfs_y.push(fy + 1);bfs_z.push(fz);
            bfs_x.push(fx);bfs_y.push(fy);bfs_z.push(fz - 1);
            bfs_x.push(fx);bfs_y.push(fy);bfs_z.push(fz + 1);
            if(!fz)
            {
                in_air = 0;
            }
        }
        bfs_x.pop();
        bfs_y.pop();
        bfs_z.pop();
    }
    if(in_air)
    {
        for(int i = 0;i < this_part[0].size();i++)
        {
            ice[this_part[0][i]][this_part[1][i]][this_part[2][i]] = 0;
            bk++;
        }
    }
    return bk;
}
int highest_wall()
{
    int mx = -1;
    for(int i = house_x;i < house_x + house_length;i++)
    {
        for(int j = house_y;j < house_y + house_width;j++)
        {
            if((i == house_x || i == house_x + house_length - 1) || (j == house_y || j == house_y + house_width - 1))
            {
                for(int k = h_limit;k >= 0;k--)
                {
                    if(ice[i][j][k])
                    {
                        mx = max(mx,k);
                        break;
                    }
                }
            }
        }
    }
    return mx;
}
void remove_block(int q1,int q2,int q3)
{
    ice[q1][q2][q3] = 0;
    ice_block_cnt++;
    broken_cnt = 0;
    memset(vis,0,sizeof(vis));
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < n;j++)
        {
            for(int l = 0;l <= h_limit;l++)
            {
                if(ice[i][j][l] && !vis[i][j][l])
                {
                    broken_cnt += bfs(i,j,l);
                }
            }
        }
    }
}
int main()
{
    cin >> n >> h_limit >> house_x >> house_y >> house_length >> house_width >> t;
    while(t--)
    {
        cin >> query;
        if(query == "ICE_BARRAGE")
        {
            cin >> q1 >> q2 >> q3 >> q4;
            x_axis = ((q3 + 2) % 4 == 0?0:(q3 == 0 || q3 == 1 || q3 == 7?-1:1));
            y_axis = (q3 % 4 == 0?0:(q3 < 4?-1:1));
            bx = q1;
            by = q2;
            freeze_cnt = 0;
            steps = 0;
            while(bx >= 0 && bx < n && by >= 0 && by < n && steps <= q4)
            {
                steps++;
                if(ice[bx][by][0])
                {
                    break;
                }
                else if(frozen[bx][by] < 4)
                {
                    frozen[bx][by]++;
                    freeze_cnt++;
                }
                bx += x_axis;
                by += y_axis;
            }
            cout << "CIRNO FREEZED " << freeze_cnt << " BLOCK(S)\n";
        }
        else if(query == "MAKE_ICE_BLOCK")
        {
            this_round_ice_block_cnt = 0;
            for(int i = 0;i < n;i++)
            {
                for(int j = 0;j < n;j++)
                {
                    if(frozen[i][j] == 4)
                    {
                        frozen[i][j] = 0;
                        ice_block_cnt++;
                        this_round_ice_block_cnt++;
                    }
                }
            }
            cout << "CIRNO MADE " << this_round_ice_block_cnt << " ICE BLOCK(S),NOW SHE HAS " << ice_block_cnt << " ICE BLOCK(S)\n";
        }
        else if(query == "PUT_ICE_BLOCK")
        {
            cin >> q1 >> q2 >> q3;
            if(!ice_block_cnt)
            {
                cout << "CIRNO HAS NO ICE_BLOCK\n";
                continue;
            }
            else if(no_blocks_around(q1,q2,q3) || ice[q1][q2][q3])
            {
                cout << "BAKA CIRNO,CAN'T PUT HERE\n";
                continue;
            }
            else if(q1 < house_x || q1 > house_x + house_length - 1 || q2 < house_y || q2 > house_y + house_width - 1)
            {
                cout << "CIRNO MISSED THE PLACE\n";
            }
            else if(house_x < q1 && q1 < house_x + house_length - 1 && house_y < q2 && q2 < house_y + house_width - 1)
            {
                cout << "CIRNO PUT AN ICE_BLOCK INSIDE THE HOUSE\n";
            }
            else
            {
                cout << "CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS " << ice_block_cnt - 1 << " ICE_BLOCK(S)\n";
            }
            ice_block_cnt--;
            ice[q1][q2][q3] = 1;
            if(!q3)
            {
                frozen[q1][q2] = 0;
            }
        }
        else if(query == "REMOVE_ICE_BLOCK")
        {
            cin >> q1 >> q2 >> q3;
            if(!ice[q1][q2][q3])
            {
                cout << "BAKA CIRNO,THERE IS NO ICE_BLOCK\n";
            }
            else
            {
                remove_block(q1,q2,q3);
                cout << "CIRNO REMOVED AN ICE_BLOCK";
                if(broken_cnt)
                {
                    cout << ",AND " << broken_cnt << " BLOCK(S) ARE BROKEN";
                }
                cout << "\n";
            }
        }
        else if(query == "MAKE_ROOF")
        {
            perfect = 1;
            roof_h = highest_wall() + 1;
            door_x = house_x + 1;
            door_y = house_y + 1;
            for(int i = house_x;i < house_x + house_length;i++)
            {
                for(int j = house_y;j < house_y + house_width;j++)
                {
                    if(!ice[i][j][roof_h])
                    {
                        roof_block_cnt++;
                        ice[i][j][roof_h] = 1;
                    }
                }
            }
            if(ice_block_cnt < roof_block_cnt)
            {
                cout << "SORRY CIRNO,NOT ENOUGH ICE_BLOCK(S) TO MAKE ROOF";
                perfect = 0;
                break;
            }
            else if(roof_h < 2 || (house_length - 2) * (house_width - 2) * roof_h < 2)
            {
                cout << "SORRY CIRNO,HOUSE IS TOO SMALL";
                perfect = 0;
                break;
            }
            ice_block_cnt -= roof_block_cnt;
            for(int i = 0;i < n;i++)
            {
                for(int j = 0;j < n;j++)
                {
                    for(int l = 0;l <= h_limit;l++)
                    {
                        if((i < house_x || i > house_x + house_length - 1 || j < house_y || j > house_y + house_width - 1 || l > roof_h) && ice[i][j][l])
                        {
                            out_ice_cnt++;
                            ice[i][j][l] = 0;
                            ice_block_cnt++;
                        }
                        else if(house_x < i && i < house_x + house_length - 1 && house_y < j && j < house_y + house_width - 1 && l < roof_h && ice[i][j][l])
                        {
                            in_ice_cnt++;
                            ice[i][j][l] = 0;
                            ice_block_cnt++;
                        }
                    }
                }
            }
            cout << in_ice_cnt << " ICE_BLOCK(S) INSIDE THE HOUSE NEED TO BE REMOVED\n" << out_ice_cnt << " ICE_BLOCK(S) OUTSIDE THE HOUSE NEED TO BE REMOVED\n";
            if(in_ice_cnt || out_ice_cnt)
            {
                perfect = 0;
            }
            broken_cnt = 0;
            memset(vis,0,sizeof(vis));
            for(int i = house_x;i < house_x + house_length;i++)
            {
                for(int j = house_y;j < house_y + house_width;j++)
                {
                    if(ice[i][j][roof_h] && !vis[i][j][roof_h])
                    {
                        broken_cnt += bfs(i,j,roof_h);
                    }
                }
            }
            if(broken_cnt)
            {
                cout << "SORRY CIRNO,HOUSE IS BROKEN WHEN REMOVING BLOCKS";
                break;
            }
            for(int i = house_x;i < house_x + house_length;i++)
            {
                for(int j = house_y;j < house_y + house_width;j++)
                {
                    if(((i == house_x || i == house_x + house_length - 1) || (j == house_y || j == house_y + house_width - 1)) && !((i == house_x || i == house_x + house_length - 1) && (j == house_y || j == house_y + house_width - 1)))
                    {
                        for(int l = 0;l < roof_h;l++)
                        {
                            if(!ice[i][j][l])
                            {
                                wall_cnt++;
                            }
                        }
                    }
                }
            }
            for(int i = house_x;i < house_x + house_length;i++)
            {
                for(int j = house_y;j < house_y + house_width;j++)
                {
                    if(((i == house_x || i == house_x + house_length - 1) || (j == house_y || j == house_y + house_width - 1)) && !((i == house_x || i == house_x + house_length - 1) && (j == house_y || j == house_y + house_width - 1)))
                    {
                        door_score = wall_cnt - (!ice[i][j][0]?1:0) - (!ice[i][j][1]?1:0);
                        if(i == house_x + 1 || i == house_x + house_length - 2 || j == house_y + 1 || j == house_y + house_width - 2)
                        {
                            if(i == house_x + 1)
                            {
                                door_score += (!ice[i][j][0] && !ice[i - 1][j][0]?1:0) + (!ice[i][j][1] && !ice[i - 1][j][1]?1:0);
                                help_corner_cnt += (!ice[i][j][0] && !ice[i - 1][j][0]?1:0) + (!ice[i][j][1] && !ice[i - 1][j][1]?1:0);
                            }
                            if(i == house_x + house_length - 2)
                            {
                                door_score += (!ice[i][j][0] && !ice[i + 1][j][0]?1:0) + (!ice[i][j][1] && !ice[i + 1][j][1]?1:0);
                                help_corner_cnt += (!ice[i][j][0] && !ice[i + 1][j][0]?1:0) + (!ice[i][j][1] && !ice[i + 1][j][1]?1:0);
                            }
                            if(j == house_y + 1)
                            {
                                door_score += (!ice[i][j][0] && !ice[i][j - 1][0]?1:0) + (!ice[i][j][1] && !ice[i][j - 1][1]?1:0);
                                help_corner_cnt += (!ice[i][j][0] && !ice[i][j - 1][0]?1:0) + (!ice[i][j][1] && !ice[i][j - 1][1]?1:0);
                            }
                            if(j == house_y + house_width - 2)
                            {
                                door_score += (!ice[i][j][0] && !ice[i][j + 1][0]?1:0) + (!ice[i][j][1] && !ice[i][j + 1][1]?1:0);
                                help_corner_cnt += (!ice[i][j][0] && !ice[i][j + 1][0]?1:0) + (!ice[i][j][1] && !ice[i][j + 1][1]?1:0);
                            }
                        }
                        door_score = 1200 - door_score + help_corner_cnt;
                        door_score *= 10;
                        door_score += (!ice[i][j][0] && !ice[i][j][1]?1:0);
                        door_score *= 10;
                        door_score += ((house_length % 2 && i == house_x + house_length / 2 || house_length % 2 == 0 && i == house_x + house_length / 2 || i == house_x + house_length / 2 - 1) || (house_width % 2 && j == house_y + house_width / 2 || house_width % 2 == 0 && j == house_y + house_width / 2 || j == house_y + house_width / 2 - 1)?1:0);
                        if(door_score > mx_door_score)
                        {
                            mx_door_score = door_score;
                            door_x = i;
                            door_y = j;
                        }
                    }
                }
            }
            wall_cnt -= (!ice[door_x][door_y][0]?1:0) + (!ice[door_x][door_y][1]?1:0);
            if(door_x == house_x + 1 || door_x == house_x + house_length - 2 || door_y == house_y + 1 || door_y == house_y + house_width - 2)
            {
                if(door_x == house_x + 1)
                {
                    wall_cnt += (!ice[door_x][door_y][0] && !ice[door_x - 1][door_y][0]?1:0) + (!ice[door_x][door_y][1] && !ice[door_x - 1][door_y][1]?1:0);
                    if(!ice[door_x][door_y][0])
                    {
                        ice[door_x - 1][door_y][0] = 1;
                    }
                    if(!ice[door_x][door_y][1])
                    {
                        ice[door_x - 1][door_y][1] = 1;
                    }
                }
                if(door_x == house_x + house_length - 2)
                {
                    wall_cnt += (!ice[door_x][door_y][0] && !ice[door_x + 1][door_y][0]?1:0) + (!ice[door_x][door_y][1] && !ice[door_x + 1][door_y][1]?1:0);
                    if(!ice[door_x][door_y][0])
                    {
                        ice[door_x + 1][door_y][0] = 1;
                    }
                    if(!ice[door_x][door_y][1])
                    {
                        ice[door_x + 1][door_y][1] = 1;
                    }
                }
                if(door_y == house_y + 1)
                {
                    wall_cnt += (!ice[door_x][door_y][0] && !ice[door_x][door_y - 1][0]?1:0) + (!ice[door_x][door_y][1] && !ice[door_x][door_y - 1][1]?1:0);
                    if(!ice[door_x][door_y][0])
                    {
                        ice[door_x][door_y - 1][0] = 1;
                    }
                    if(!ice[door_x][door_y][1])
                    {
                        ice[door_x][door_y - 1][1] = 1;
                    }
                }
                if(door_y == house_y + house_width - 2)
                {
                    wall_cnt += (!ice[door_x][door_y][0] && !ice[door_x][door_y + 1][0]?1:0) + (!ice[door_x][door_y][1] && !ice[door_x][door_y + 1][1]?1:0);
                    if(!ice[door_x][door_y][0])
                    {
                        ice[door_x][door_y + 1][0] = 1;
                    }
                    if(!ice[door_x][door_y][1])
                    {
                        ice[door_x][door_y + 1][1] = 1;
                    }
                }
            }
            if(wall_cnt > ice_block_cnt)
            {
                cout << "SORRY CIRNO,NOT ENOUGH ICE_BLOCKS TO FIX THE WALL";
                break;
            }
            ice_block_cnt -= wall_cnt;
            cout << "GOOD JOB CIRNO,SUCCESSFULLY BUILT THE HOUSE\n";
            if(!ice[door_x][door_y][0] && !ice[door_x][door_y][1])
            {
                cout << "DOOR IS OK\n";
            }
            else
            {
                cout << "HOUSE HAS NO DOOR\n";
                perfect = 0;
                ice_block_cnt += (ice[door_x][door_y][0]?1:0) + (ice[door_x][door_y][1]?1:0);
            }
            if(wall_cnt)
            {
                cout << "WALL NEED TO BE FIXED\n";
                perfect = 0;
            }
            else
            {
                cout << "WALL IS OK\n";
            }
            for(int i = house_x;i < house_x + house_length;i++)
            {
                for(int j = house_y;j < house_y + house_width;j++)
                {
                    if((i == house_x || i == house_x + house_length - 1) && (j == house_y || j == house_y + house_width - 1))
                    {
                        for(int l = 0;l < roof_h;l++)
                        {
                            if(!ice[i][j][l])
                            {
                                corner_cnt++;
                            }
                        }
                    }
                }
            }
            if(corner_cnt)
            {
                cout << "CORNER NEED TO BE FIXED\n";
                perfect = 0;
            }
            else
            {
                cout << "CORNER IS OK\n";
            }
            ice_block_cnt = max(ice_block_cnt - corner_cnt,0);
            cout << "CIRNO FINALLY HAS " << ice_block_cnt << " ICE_BLOCK(S)\n";
            if(perfect && ((house_length % 2 && door_x == house_x + house_length / 2 || house_length % 2 == 0 && door_x == house_x + house_length / 2 || door_x == house_x + house_length / 2 - 1) || (house_width % 2 && door_y == house_y + house_width / 2 || house_width % 2 == 0 && door_y == house_y + house_width / 2 || door_y == house_y + house_width / 2 - 1)))
            {
                cout << "CIRNO IS PERFECT!";
            }
        }
    }
    return 0;
}

:::

AC 记录

后记

出题人我爱你!!!!!