列表

详情


NC205054. BuildtheHuoshenshanHospital

描述

Description

ZSGW is a cute Hamster studying civil engineering in the Wuhan Hamster University (aka: WHU).

Due to the outbreak of the COVID-19, the local government planned to build two more hospitals, named HSS and LSS, to rescue the increasing number of patients. To finish the construction as quickly as possible, ZSGW also participated in this great task.

The first thing to build the hospital is to build the main frame. For simplicity, the main frames will be built by the basic unit, which can be considered as cube formed by steel bars. Account for the different requirements in different places, there will be four types of basic unit to be used.

We will describe these unit in the following way: Firstly, we named the eight vertices of the cube as the following image:






  1. A-type unit, the most simple one, where 12 bars lies on the edges of the cube. That is, A-type unit has 12 bars connecting (A, B), (A, C), (C, D), (B, D), (E, F), (E, G), (G, H), (H, F), (C, G), (D, H), (B, F), (A, E)。
  2. B-type unit, based on the A-type unit, it has one more bar on the diagonal of each of the 6 faces of the cube, which means apart from the bars on the A-type unit, B type unit has 6 more bars connecting (A, D), (D, F), (F, A), (C, H), (H, E), (E, C)。
  3. C-type unit, which add one more bar on the another diagonal of the face, has 6 more bars than the B-type unit, which are (B, C), (B, H), (B, E), (G, D), (G, F), (G, A)。
  4. D-type unit, based on the C-type unit, it removed all the crossing bars except the top and the bottom face, so it only has bars connecting (A, D), (C, B), (G, F), (E, H) and bars of the A-type.

For simplicity, you don't need to consider the rotation of these units, therefore face is always on the top and face is always in the front and face is always on the left.

The main frame then can be regarded as these units piling up one by one and face to face. Moreover, if there are two bars coincide on the touching face of two units, we can save one of the bars. For example, if we need to build the frame which is piled up by two A-type unit, we will using only 20 bars instead of 24.

Now ZSGW has got the blueprint of the main frame, he wonders how many steel bars are needed to build the main frame.

It's an emergency task, so please gkd as much as possible!

输入描述

The input contains multiple cases. The first line contains an integer , the number of test cases.

Each cases started with three integers , denoted the size of the frame.

The following part contains  lines of  characters, each  lines described a cross section of the frame, from the bottom to the top in order. For each  matrix, each character described the unit at this place. the uppercase letter from A to D refer to that kind of unit, and the dot '.' means that there is no unit at this place.

Therefore, if the -th row and -th column of the -th matrix contains a letter 'A', the position  lies a A-type unit according to the Cartesian coordinate system.

for each test case, all the given numbers are no more than , and for all test cases .

输出描述

For each test case, print a number  in one line, denoting the required numbers of steel bars to build the frame.

示例1

输入:

4
1 1 1
A
1 1 2
A
A
2 2 2
AB
.A
.A
..
2 2 2
A.
.A
.A
..

输出:

12
20
42
33

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++11(clang++ 3.9) 解法, 执行用时: 43ms, 内存消耗: 5616K, 提交时间: 2020-05-04 20:46:20

#include<bits/stdc++.h>
using namespace std;
const int N=55;
char s[N][N][N];
int a[N][N][N],b[N][N][N],c[N][N][N],d[N][N][N],e[N][N][N],f[N][N][N];
void work1(char x,int i,int j,int k){
	if(x=='.')return;
	for(int u=0;u<=1;u++)for(int v=0;v<=1;v++){
		a[i][j+u][k+v]=max(a[i][j+u][k+v],1);
		b[i+u][j][k+v]=max(b[i+u][j][k+v],1);
		c[i+u][j+v][k]=max(c[i+u][j+v][k],1);
	}
	if(x=='D'){d[i][j][k]=max(2,d[i][j][k]),d[i+1][j][k]=max(2,d[i+1][j][k]);return;}
	if(x=='B'){
		d[i][j][k]=max(1,d[i][j][k]),d[i+1][j][k]=max(1,d[i+1][j][k]);
		e[i][j][k]=max(1,e[i][j][k]),e[i][j+1][k]=max(1,e[i][j+1][k]);
		f[i][j][k]=max(1,f[i][j][k]),f[i][j][k+1]=max(1,f[i][j][k+1]);
	}
	if(x=='C'){
		d[i][j][k]=max(2,d[i][j][k]),d[i+1][j][k]=max(2,d[i+1][j][k]);
		e[i][j][k]=max(2,e[i][j][k]),e[i][j+1][k]=max(2,e[i][j+1][k]);
		f[i][j][k]=max(2,f[i][j][k]),f[i][j][k+1]=max(2,f[i][j][k+1]);
	}
}
void work(){
	int r,C,h;scanf("%d%d%d",&r,&C,&h);
	for(int i=1;i<=h;i++){
		for(int j=1;j<=r;j++)scanf("%s",s[i][j]+1);
	}
	int ans=0;
	for(int i=1;i<=h+1;i++){
		for(int j=1;j<=r+1;j++){
			for(int k=1;k<=C+1;k++){
				a[i][j][k]=b[i][j][k]=c[i][j][k]=d[i][j][k]=e[i][j][k]=f[i][j][k]=0;
			}
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=r;j++){
			for(int k=1;k<=C;k++){
				work1(s[i][j][k],i,j,k);
			}
		}
	}
	for(int i=1;i<=h+1;i++){
		for(int j=1;j<=r+1;j++){
			for(int k=1;k<=C+1;k++){
				ans+=a[i][j][k]+b[i][j][k]+c[i][j][k]+d[i][j][k]+e[i][j][k]+f[i][j][k];
			}
		}
	}
	printf("%d\n",ans);
}
int main(){
	int T=1;
	scanf("%d",&T);
	while(T--)work();
	return 0;
} 

C++14(g++5.4) 解法, 执行用时: 71ms, 内存消耗: 8940K, 提交时间: 2020-04-26 15:56:39

#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,f) for(int i=s;i<f;++i)
#define per(i,s,f) for(int i=s;i>f;--i)
const int maxn = 60;
int t, r, c, h;
char in[maxn];
int fr[maxn][maxn][maxn];
int num[5] = { 0,12,18,24,20 };
int bar[maxn][maxn][maxn][9];
int sample[4][9] = {
	{1,0,0,1,0,0,1,0,0},
	{1,1,0,1,1,0,1,0,1},
	{1,1,1,1,1,1,1,1,1},
	{1,1,1,1,0,0,1,0,0},
};
int unit[4][8][9];
void build(int x,int y,int z,int t) {
	if (t == 0) return;
	int *s = sample[t - 1];
	int *p = bar[z][y][x];
	rep(i, 0, 9) p[i] += s[i];
	p = bar[z+1][y][x];
	p[1] += s[1], p[2] += s[2], p[3] += s[3], p[6] += s[6];
	p = bar[z][y+1][x];
	p[4] += s[4], p[5] += s[5], p[0] += s[0], p[6] += s[6];
	p = bar[z][y][x+1];
	p[7] += s[7], p[8] += s[8], p[0] += s[0], p[3] += s[3];
	p = bar[z][y + 1][x + 1];
	p[0] += s[0];
	p = bar[z + 1][y][x + 1];
	p[3] += s[3];
	p = bar[z + 1][y + 1][x];
	p[6] += s[6];

}
int main()
{
	scanf("%d", &t);
	while (t--) {
		memset(fr, 0, maxn*maxn*maxn * sizeof(int));
		memset(bar, 0, maxn*maxn*maxn * 9 * sizeof(int));
		scanf("%d %d %d", &r, &c, &h);
		rep(i, 0, h) rep(j, 0, r) {
			scanf("%s", in);
			rep(k, 0, c) {
				int ink = in[k];
				if (ink == '.') ink = 0;
				else ink -= 'A' - 1;
				fr[i][j][k] = ink;
			}
		}
		int sum = 0;
		rep(i, 0, h) rep(j, 0, r)rep(k, 0, c) {
			build(k, j, i, fr[i][j][k]);
		}
		rep(i, 0, h+1) rep(j, 0, r+1)rep(k, 0, c+1) {
			int *p = bar[i][j][k];
			rep(w, 0, 9) if (p[w]) sum++;
		}
		printf("%d\n", sum);
	}
}

上一题