NC205054. BuildtheHuoshenshanHospital
描述
输入描述
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); } }