题面
显然模拟即可
操作一:普及T1(早年)水平 直接for一遍就好了,记得判断出界或撞冰砖
操作二:普及T1(近年)水平,直接for一遍就好了
操作三:普及T1(早年)水平,判断一下有没有,是否连的上即可 记得地面冰冻度清零
操作四:普及T2水平,由于数据范围很小,移走后直接对整图bfs判断是否接地即可
操作五:
有点烦琐
首先是造房顶,普及T2水平,max出高度然后for一遍就好了
接着是清理垃圾
由于一定存在一种方式使得没有一个冰砖破碎
所以直接内外拿掉再整图bfs一遍算墙上要拿多少
记得判断房顶塌陷,房间过小
然后补残缺,重点来了
注意一下加红的大多数
因为当门开在转角边上是要清理拐角的,因为房子里看的到
好像题解里的老哥用了一大堆分类讨论
其实并不用
只要暴力枚举门的位置,然后算出来就可以了
然后注意:当需要冰砖数相同的时候,应尽可能让拐角空位少一些,然后尽可能达到perfect
也就是以(需要砖块数,拐角空位,完美)进行三关键字排序
然后造门
然后造角
最后判断完美,以下条件缺一不可:1.门天然形成,开在正中间 2.不用填墙 3.不用补拐角 4.不需要清理垃圾
然后就做完了
坑点不是很多,主要是那个柱子有的时候需要填补,以及最后一行不换行(Too long on line 1001???)
js里输出有两个:console.log()换行 和 process.stdout.write()不换行(查了半天才查到)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282 ;
const IO = require("readline").createInterface(process.stdin, process.stdout);
var nowline = 0, n, hm, sx, sy, ex, ey, m;
var optlist = [];
var map = [], ice = [];
IO.on("close", function () {
process.exit();
});
var blockcnt = 0;
var fx = [-1, -1, 0, 1, 1, 1, 0, -1], fy = [0, -1, -1, -1, 0, 1, 1, 1];
function inmap(x, y, z) {
return x >= 0 && x < n && y >= 0 && y < n && z >= 0 && z <= hm;
}
var get_size = (function() {
var fx = [1, -1, 0, 0, 0, 0], fy = [0, 0, 1, -1, 0, 0], fz = [0, 0, 0, 0, 1, -1];
return function(x, y, z) {
var ans = 0;
for(let i = 0; i < 6; i++)
if(inmap(x + fx[i], y + fy[i], z + fz[i])) ans += map[x + fx[i]][y + fy[i]][z + fz[i]];
else if(z + fz[i] < 0) ans++;
return ans;
}
})();//两个方向数组,不想用两个变量名
function ice_barrage(x, y, d, s) {
x = Number(x), y = Number(y), d = Number(d), s = Number(s);
var ans = 0;
for(var i = 0; i <= s; i++) {
// process.stdout.write(inmap(x, y, 0) + ' ' + map[x][y][0]);
// process.stdout.write(x + ' ' + y + ' ' + 0);
if(inmap(x, y, 0) && map[x][y][0] == 0) {
if(ice[x][y] < 4) ice[x][y]++, ans++;
}
else break;
x = x + fx[d], y = y + fy[d];
}
process.stdout.write("CIRNO FREEZED " + ans + " BLOCK(S)");
}//操作1
function make_ice_block() {
var ans = 0;
for(var i = 0; i < n; i++)
for(var j = 0; j < n; j++) if(ice[i][j] == 4) ice[i][j] = 0, ans++;
process.stdout.write("CIRNO MADE " + ans + " ICE BLOCK(S),NOW SHE HAS " + (ans + blockcnt) + " ICE BLOCK(S)");
blockcnt += ans;
}//操作2
function inroom(x, y) {
return x > sx && x < ex && y > sy && y < ey;
}//严格在屋子里面
function outroom(x, y) {
return x < sx || x > ex || y < sy || y > ey;
}//严格在屋子外面 不管屋顶
function put_ice_block(x, y, z) {
x = Number(x), y = Number(y), z = Number(z);
if(blockcnt == 0) process.stdout.write("CIRNO HAS NO ICE_BLOCK");
else if(!inmap(x, y, z) || map[x][y][z] || get_size(x, y, z) == 0) process.stdout.write("BAKA CIRNO,CAN'T PUT HERE");
else {
map[x][y][z] = 1;
if(z == 0) ice[x][y] = 0;//注意!!!
blockcnt -= 1;
if(outroom(x, y)) process.stdout.write("CIRNO MISSED THE PLACE");
else if(inroom(x, y)) process.stdout.write("CIRNO PUT AN ICE_BLOCK INSIDE THE HOUSE");
else process.stdout.write("CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS " + blockcnt + " ICE_BLOCK(S)");
}
}
var updata;//bfs找破碎冰砖数(详情见main函数里)
function remove_ice_block(x, y, z) {
x = Number(x), y = Number(y), z = Number(z);
if(!inmap(x, y, z) || map[x][y][z] == 0) process.stdout.write("BAKA CIRNO,THERE IS NO ICE_BLOCK");
else {
map[x][y][z] = 0;
let k = updata();
if(k != 0) process.stdout.write("CIRNO REMOVED AN ICE_BLOCK,AND " + k + " BLOCK(S) ARE BROKEN");
else process.stdout.write("CIRNO REMOVED AN ICE_BLOCK");
blockcnt++;
}
}//操作4
var hei = -1, _fixc = 0;//屋顶高度,以及填补的拐角空位数量
function get_wall_size(doorx, doory) {
var ans = _fixc = 0;
for(let i = 0; i < n; i++)
for(let j = 0; j < n; j++) {
if(inroom(i, j) || outroom(i, j)) continue;
if(i == doorx && j == doory)
for(let h = 2; h < hei; h++) ans += 1 - map[i][j][h];
else if((i != sx && i != ex) || (j != sy && j != ey))
for(let h = 0; h < hei; h++) ans += 1 - map[i][j][h];
else if(Math.abs(i - doorx) + Math.abs(j - doory) == 1)
ans += 2 - map[i][j][0] - map[i][j][1], _fixc += 2 - map[i][j][0] - map[i][j][1];
}
return ans;
}//当门在(doorx,doory)时,需要填补的空位数
function get_corner_size(cx, cy) {
var ans = 0;
for(let i = 0; i < hei; i++) ans += 1 - map[cx][cy][i], map[cx][cy][i] = 1;
return ans;
}//填拐角
function fix_wall(doorx, doory) {
for(let i = 0; i < n; i++)
for(let j = 0; j < n; j++) {
if(inroom(i, j) || outroom(i, j)) continue;
if(i == doorx && j == doory)
for(let h = 2; h < hei; h++) map[i][j][h] = 1;
else if((i != sx && i != ex) || (j != sy && j != ey))
for(let h = 0; h < hei; h++) map[i][j][h] = 1;
else if(Math.abs(i - doorx) + Math.abs(j - doory) == 1)
map[i][j][0] = map[i][j][1] = 1;
}
}//填墙(其实就是get_wall_size改了一下)
function per(doorx, doory) {
if(map[doorx][doory][0] || map[doorx][doory][1]) return 0;
if((doorx == sx || doorx == ex) && Math.abs((sy + ey) / 2 - doory) < 0.9) return 1;
if((doory == sy || doory == ey) && Math.abs((sx + ex) / 2 - doorx) < 0.9) return 1;
return 0;
}//门的位置完美
function make_roof() {
for(let i = 0; i < n; i++)
for(let j = 0; j < n; j++) {
if(inroom(i, j) || inroom(i, j)) continue;
for(let h = hei + 1; h < hm; h++) if(map[i][j][h]) hei = h;
}
hei++;//算屋顶高度
var cnt = 0;
for(let i = sx; i <= ex; i++)
for(let j = sy; j <= ey; j++) cnt += 1 - map[i][j][hei];
if(cnt > blockcnt) {
process.stdout.write("SORRY CIRNO,NOT ENOUGH ICE_BLOCK(S) TO MAKE ROOF");
return;
}
blockcnt -= cnt;
if(hei < 2 || (ex - sx - 1) * (ey - sy - 1) <= 1) {//空间过小
process.stdout.write("SORRY CIRNO,HOUSE IS TOO SMALL");
return;
}
for(let i = sx; i <= ex; i++)
for(let j = sy; j <= ey; j++) map[i][j][hei] = 1;//造房顶
var k1 = 0, k2 = 0;
for(let i = 0; i < n; i++)
for(let j = 0; j < n; j++)
for(let h = 0; h < hm; h++) {
if(inroom(i, j) && h < hei) k1 += map[i][j][h], map[i][j][h] = 0;//在屋子里面
else if(outroom(i, j) || h > hei) k2 += map[i][j][h], map[i][j][h] = 0;//外面
}
var k3 = updata();//"碎掉"的块数即为墙上拆掉的块数
blockcnt += k1 + k2 + k3;
process.stdout.write(k1 + " ICE_BLOCK(S) INSIDE THE HOUSE NEED TO BE REMOVED\n");
process.stdout.write(k2 + " ICE_BLOCK(S) OUTSIDE THE HOUSE NEED TO BE REMOVED\n");
if(map[sx][sy][hei] == 0) {
process.stdout.write("SORRY CIRNO,HOUSE IS BROKEN WHEN REMOVING BLOCKS");
return;
}//塌了
var doorx, doory, wallcnt = 100000000, doorneed, cornerneed, doorp = 0, _maxfix = 0;
for(let i = 0; i < n; i++)
for(let j = 0; j < n; j++) {
if(inroom(i, j) || outroom(i, j)) continue;
if((i == sx || i == ey) && (j == sy || j == ey)) continue;
var newcost = get_wall_size(i, j);
if(wallcnt == newcost) {
if(_maxfix < _fixc) doorx = i, doory = j, wallcnt = newcost, _maxfix = _fixc, doorp = per(i, j);
if(_maxfix == _fixc && per(i, j)) doorx = i, doory = j, wallcnt = newcost, _maxfix = _fixc, doorp = per(i, j);
}
if(wallcnt > newcost) doorx = i, doory = j, wallcnt = newcost, _maxfix = _fixc, doorp = per(i, j);//三关键字找最优解
}
if(wallcnt > blockcnt) {
process.stdout.write("SORRY CIRNO,NOT ENOUGH ICE_BLOCKS TO FIX THE WALL");
return;
}
blockcnt -= wallcnt;
process.stdout.write("GOOD JOB CIRNO,SUCCESSFULLY BUILT THE HOUSE\n");
if(map[doorx][doory][0] + map[doorx][doory][1] != 0) {
process.stdout.write("HOUSE HAS NO DOOR\n");
doorneed = 1;
blockcnt += map[doorx][doory][0] + map[doorx][doory][1];
map[doorx][doory][0] = map[doorx][doory][1] = 0;
}
else process.stdout.write("DOOR IS OK\n");
if(wallcnt > 0) process.stdout.write("WALL NEED TO BE FIXED\n");
else process.stdout.write("WALL IS OK\n");
fix_wall(doorx, doory);
cornerneed = get_corner_size(sx, sy) + get_corner_size(ex, sy) + get_corner_size(sx, ey) + get_corner_size(ex, ey);
blockcnt -= cornerneed;
if(blockcnt < 0) blockcnt = 0;
if(cornerneed > 0) process.stdout.write("CORNER NEED TO BE FIXED\n");
else process.stdout.write("CORNER IS OK\n");
process.stdout.write("CIRNO FINALLY HAS " + blockcnt + " ICE_BLOCK(S)");
if(cornerneed || doorneed || wallcnt || k1 || k2) return;
if(doorp) process.stdout.write("\nCIRNO IS PERFECT!");
}
function main() {
updata = (function() {
var fx = [0, 0, 0, 0, 1, -1], fy = [0, 0, 1, -1, 0, 0], fz = [1, -1, 0, 0, 0, 0];
var vis = [];
for(let i = 0; i < n; i++) {
vis.push([]);
for(let j = 0; j < n; j++) {
vis[i].push([]);
for(let k = 0; k <= hm; k++) vis[i][j].push(0);
}
}
return function() {
var qx = [], qy = [], qz = [], head = 0, tail = -1;
for(let i = 0; i < n; i++)
for(let j = 0; j < n; j++) {
for(let k = 0; k <= hm; k++) vis[i][j][k] = 0;
if(map[i][j][0] == 1) {
vis[i][j][0] = 1;
qx.push(i), qy.push(j), qz.push(0);
tail++;
}
}
var ans = 0;
while(head <= tail) {
for(let i = 0, nx, ny, nz; i < 6; i++) {
nx = qx[head] + fx[i], ny = qy[head] + fy[i], nz = qz[head] + fz[i];
if(inmap(nx, ny, nz) && map[nx][ny][nz] == 1 && vis[nx][ny][nz] == 0) {
vis[nx][ny][nz] = 1;
tail++;
qx.push(nx), qy.push(ny), qz.push(nz);
}
}
head++;
}
for(let i = 0; i < n; i++)
for(let j = 0; j < n; j++)
for(let k = 0; k <= hm; k++)
if(map[i][j][k] == 1 && vis[i][j][k] == 0) ans++, map[i][j][k] = 0;
return ans;
};
})();
for(let i = 0; i < n; i++) {
map.push([]);
ice.push([]);
for(let j = 0; j < n; j++) {
ice[i].push(0);
map[i].push([]);
for(let k = 0; k <= hm; k++) map[i][j].push(0);
}
}
for(let i = 0; i < m; i++) {
let list = optlist[i].trim().split(' ');
if(list[0] == "ICE_BARRAGE") ice_barrage(list[1], list[2], list[3], list[4]);
else if(list[0] == "MAKE_ICE_BLOCK") make_ice_block();
else if(list[0] == "PUT_ICE_BLOCK") put_ice_block(list[1], list[2], list[3]);
else if(list[0] == "REMOVE_ICE_BLOCK") remove_ice_block(list[1], list[2], list[3]);
else if(list[0] == "MAKE_ROOF") make_roof();
if(i != m - 1) process.stdout.write("\n");
}
IO.close();
}
IO.on("line", function (line) {
nowline++;
if(nowline == 1) n = Number(line.trim());
if(nowline == 2) hm = Number(line.trim());
if(nowline == 3) {
let list = line.trim().split(' ').map(a => Number(a));
sx = list[0], sy = list[1];
ex = list[0] + list[2] - 1, ey = list[1] + list[3] - 1;
}
if(nowline == 4) m = Number(line);
if(nowline > 4) {
optlist.push(line);
if(nowline == m + 4) main();
}
});//读入(我习惯用readline)
刚学js,大佬轻喷