标签:之间 ati time ssi source day memory ber review
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1808 Accepted Submission(s): 1138
#include<stdio.h> #include<iostream> #include<algorithm> using namespace std; #define N 55 int map[N][N],Next[2][4]={0,1,1,0,-1,0,0,-1}; int main() { int t,m,n,i,j,k,sum,ans,x,y; scanf("%d",&t); while(t --) { scanf("%d%d",&n,&m); sum = ans=0; for(i = 1; i <= n; i ++) { for(j = 1; j <= m; j ++) { scanf("%d",&map[i][j]); sum += map[i][j];//计算总的砖块数 if(map[i][j]> 0)//ans记录底面面积总数 ans ++; } } sum *= 6;//初始化总的表面积 for(i = 1; i <= n; i ++) { for(j = 1; j <= m; j ++) { if(map[i][j] > 0)//房子高度大于0时 sum = sum - (map[i][j]-1)*2;//每个房子上下相邻的砖块有(高度map[i][j]-1)块 for(k = 0; k < 4; k ++)//搜索4个方向 { x = Next[0][k] + i; y = Next[1][k] + j; if(x < 1||y < 1||x>n||y>m) continue; sum -= min(map[x][y],map[i][j]);//减去两个房子相邻的公共部分面积 } } } printf("%d\n",sum-ans);//总的表面积减去底面面积 } return 0; }
hdu 5538 House Building 【矩阵表面积】
标签:之间 ati time ssi source day memory ber review
原文地址:http://www.cnblogs.com/chengdongni/p/7521526.html