HDU - 5538 L - House Building (幾何)
阿新 • • 發佈:2018-11-14
連結:
https://vjudge.net/problem/271417/origin
題意:
給出每個n行m列地圖每個位置方塊的高度,問表面積多少,不包括底面。
思路:
按順序處理方塊,每個方塊只考慮它左邊和後邊的位置的方塊。當然要多補一行一列全是零的資料。
#include <bits/stdc++.h> using namespace std; typedef long long ll; int a[52][52]; int t,n,m; int main() { for(cin>>t; t--;) { memset(a,0,sizeof a); cin>>n>>m; for(int i = 1 ; i <= n ; i++) for(int j = 1 ; j <= m; j++) cin>>a[i][j]; int ans = 0; for(int i = 1; i <= n+1; i++) { for(int j = 1; j <= m+1; j++) { ans += abs(a[i][j] - a[i][j-1]); ans += abs(a[i][j] - a[i-1][j]); if(a[i][j]) ans++; } } cout<<ans<<endl; } return 0; }