P3693 琪露诺的冰雪小屋
WA了11个点,求各位大佬当我看看哪错了!!!
#include<stdio.h>
#include<string.h>
#include<stdbool.h>
void ice_barrage(int r, int c, int d, int s);
void make_ice_block(void);
void put_ice_block(int r, int c, int h);
void remove_ice_block(int r, int c, int h);
void make_roof(void);
void dfs(int x, int y, int z);
const int x[8]={-1,-1,0,1,1,1,0,-1}, y[8]={0,-1,-1,-1,0,1,1,1};
const int xx[6]={-1,1,0,0,0,0}, yy[6]={0,0,-1,1,0,0}, zz[6]={0,0,0,0,-1,1};
bool ice[20][20][25], vis[20][20][25], perfect=true;
char str[20];
int n, hm, hr, hc, hx, hy, m, ice_cnt, highest, arr[20][20];
int main()
{
scanf("%d%d%d%d%d%d%d", &n, &hm, &hr, &hc, &hx, &hy, &m);
for(int i=0; i<m; i++)
{
scanf(" %s", str);
if(strcmp(str, "ICE_BARRAGE")==0)
{
int r, c, d, s;
scanf("%d%d%d%d", &r, &c, &d, &s);
ice_barrage(r, c, d, s);
}
else if(strcmp(str, "MAKE_ICE_BLOCK")==0)
{
make_ice_block();
}
else if(strcmp(str, "PUT_ICE_BLOCK")==0)
{
int r, c, h;
scanf("%d%d%d", &r, &c, &h);
put_ice_block(r, c, h);
}
else if(strcmp(str, "REMOVE_ICE_BLOCK")==0)
{
int r, c, h;
scanf("%d%d%d", &r, &c, &h);
remove_ice_block(r, c, h);
}
else if(strcmp(str, "MAKE_ROOF")==0)
{
make_roof();
}
}
return 0;
}
void ice_barrage(int r, int c, int d, int s)
{
int px=r, py=c, cnt=0;
for(int i=0; i<=s; i++)
{
if(px<0 || py<0 || px>=n || py>=n || ice[px][py][0])
break;
if(arr[px][py] < 4)
arr[px][py]++, cnt++;
px+=x[d], py+=y[d];
}
printf("CIRNO FREEZED %d BLOCK(S)\n", cnt);
return;
}
void make_ice_block(void)
{
int cnt=0;
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
if(arr[i][j] == 4)
arr[i][j] = 0, cnt++;
}
}
ice_cnt += cnt;
printf("CIRNO MADE %d ICE BLOCK(S),NOW SHE HAS %d ICE BLOCK(S)\n", cnt, ice_cnt);
}
void put_ice_block(int r, int c, int h)
{
if(ice_cnt == 0)
{
puts("CIRNO HAS NO ICE_BLOCK");
return;
}
else if((h!=0 && !((h<=hm-2&&ice[r][c][h+1]) || (h!=0&&ice[r][c][h-1]) || (r+1<n&&ice[r+1][c][h]) || (r!=0&&ice[r-1][c][h])
|| (c+1<n&&ice[r][c+1][h]) || (c!=0&&ice[r][c-1][h]))) || ice[r][c][h])
{
puts("BAKA CIRNO,CAN'T PUT HERE");
}
else if(r<hr||r>hr+hx-1||c<hc||c>hc+hy-1)
{
puts("CIRNO MISSED THE PLACE");
highest = highest < h ? h : highest;
ice_cnt--, ice[r][c][h] = true;
}
else if(hr+1<=r&&r<=hr+hx-2&&hc+1<=c&&c<=hc+hy-2)
{
puts("CIRNO PUT AN ICE_BLOCK INSIDE THE HOUSE");
highest = highest < h ? h : highest;
ice_cnt--, ice[r][c][h] = true;
}
else
{
printf("CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS %d ICE_BLOCK(S)\n", --ice_cnt);
highest = highest < h ? h : highest;
ice[r][c][h] = true;
}
if(h==0 && ice[r][c][h])
{
arr[r][c] = 0;
}
}
void remove_ice_block(int r, int c, int h)
{
if(!ice[r][c][h])
{
puts("BAKA CIRNO,THERE IS NO ICE_BLOCK");
}
else
{
ice[r][c][h]=false, ice_cnt++;
puts("CIRNO REMOVED AN ICE_BLOCK");
}
}
void make_roof(void)
{
int cnt=0, place=0;
for(int i=hr; i<hr+hx; i++)
{
for(int j=hc; j<hc+hy; j++)
{
if(!ice[i][j][highest+1])
{
cnt++, ice[i][j][highest+1]=true;
}
}
}
place = hx*hy*highest;
if(ice_cnt < cnt)
{
puts("SORRY CIRNO,NOT ENOUGH ICE_BLOCK(S) TO MAKE ROOF");
}
else if(highest < 2 || place < 2)
{
puts("SORRY CIRNO,HOUSE IS TOO SMALL");
}
else
{
int block=0;
ice_cnt -= cnt;
int k1=0, k2=0;
for(int i=hr+1; i<hr+hx-1; i++)
{
for(int j=hc+1; j<hc+hy-1; j++)
{
for(int k=0; k<highest; k++)
{
if(ice[i][j][k])
{
k1++;
ice[i][j][k]=false;
}
}
}
}
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
for(int k=0; k<hm; k++)
{
if((i<hr&&j<hc||i>hr+hx&&j>hc+hy)&&ice[i][j][k])
{
k2++;
ice[i][j][k]=false;
}
}
}
}
printf("%d ICE_BLOCK(S) INSIDE THE HOUSE NEED TO BE REMOVED\n", k1);
printf("%d ICE_BLOCK(S) OUTSIDE THE HOUSE NEED TO BE REMOVED\n", k2);
ice_cnt += k1+k2;
int fix=0, fix_corner=0, door_x=0, door_y=0;
bool has_door=false, fake_door=false;
for(int i=hr+1; i<hr+hx-1; i++)
{
for(int j=0; j<=highest; j++)
{
if(!ice[i][hc][j])
{
fix++;
perfect=false;
ice[i][hc][j]=true;
}
if(!ice[i][hc+hy-1][j])
{
fix++;
perfect=false;
ice[i][hc+hy-1][j]=true;
}
}
}
for(int i=hc+1; i<hc+hy-1; i++)
{
for(int j=0; j<=highest; j++)
{
if(!ice[hr][i][j])
{
fix++;
perfect=false;
ice[hr][i][j]=true;
}
if(!ice[hr+hx-1][i][j])
{
fix++;
perfect=false;
ice[hr+hx-1][i][j]=true;
}
}
}
for(int i=hr+1; i<hr+hx-1 && !has_door; i++)
{
if(!ice[i][hc][0] && !ice[i][hc][1])
{
has_door = true;
door_x = i, door_y = hc;
}
else if(!ice[i][hc][0] || !ice[i][hc][1])
{
fake_door = true;
}
if(!ice[i][hc+hy-1][0] && !ice[i][hc+hy-1][1])
{
has_door = true;
door_x = i, door_y = hc+hy-1;
}
else if(!ice[i][hc+hy-1][0] || !ice[i][hc+hy-1][1])
{
fake_door = true;
}
}
for(int i=hc+1; i<hc+hy-1 && !has_door; i++)
{
if(!ice[hr][i][0] && !ice[hr][i][1])
{
has_door = true;
door_x = hr, door_y = i;
}
else if(!ice[hr][i][0] || !ice[hr][i][1])
{
fake_door = true;
}
if(!ice[hr+hx-1][i][0] && !ice[hr+hx-1][i][1])
{
has_door = true;
door_x = i, door_y = i;
}
else if(!ice[hr+hx-1][i][0] || !ice[hr+hx-1][i][1])
{
fake_door = true;
}
}
for(int i=hr; i<hr+hx; i++)
{
for(int j=hc; j<hc+hy; j++)
{
if((i!=hr&&i!=hr+hx-1)||(j!=hc&&j!=hc+hy-1))
{
continue;
}
for(int k=0; k<=highest; k++)
{
if(!ice[i][j][k])
{
fix_corner++;
}
}
}
}
if(ice_cnt < fix)
{
puts("SORRY CIRNO,NOT ENOUGH ICE_BLOCKS TO FIX THE WALL");
}
else
{
puts("GOOD JOB CIRNO,SUCCESSFULLY BUILT THE HOUSE");
if(has_door)
{
puts("DOOR IS OK");
}
else
{
puts("HOUSE HAS NO DOOR");
perfect = false;
if(fake_door)
fix -= 1;
else
ice_cnt += 2;
}
if(fix <= 0)
{
puts("WALL IS OK");
fix = 0;
}
else
{
puts("WALL NEED TO BE FIXED");
perfect = false;
}
if(!fix_corner)
{
puts("CORNER IS OK");
}
else
{
puts("CORNER NEED TO BE FIXED");
perfect = false;
}
ice_cnt -= fix+fix_corner;
ice_cnt = ice_cnt > 0 ? ice_cnt : 0;
printf("CIRNO FINALLY HAS %d ICE_BLOCK(S)\n", ice_cnt);
if(perfect)
{
puts("CIRNO IS PERFECT!");
}
}
}
}
void dfs(int x, int y, int z)
{
if(x<0||y<0||z<0||x>=n||y>=n||z>highest||!ice[x][y][z]||vis[x][y][z])
return;
vis[x][y][z] = true;
for(int i=0; i<6; i++)
{
int px=x+xx[i], py=y+yy[i], pz=z+zz[i];
dfs(px, py, pz);
}
}