House Building---hdu5538(求表面积水题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5538

题意:有一个三维的图形,先给出平面图是n*m的矩形,每个位置都有不同个数的方块,a[i][j]代表当前位置有a[i][j]个方块,就是高度;现要求三维图形的表面积,方块的边长为1;

简单的水题,直接看一下每个位置的方块有几个面可以漏出来就可以了;

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<set>
using namespace std;
#define met(a, b) memset(a, b, sizeof(a))
#define N 105
#define INF 0x3f3f3f3f
typedef long long LL;

int dir[4][2] = { {1,0}, {-1,0}, {0,1}, {0,-1} };
int a[N][N];

int main()
{
    int T, n, m;
    LL ans;
    scanf("%d", &T);
    while(T--)
    {
        met(a, 0);
        scanf("%d %d", &m, &n);
        for(int i=1; i<=m; i++)
        {
            for(int j=1; j<=n; j++)
                scanf("%d", &a[i][j]);
        }
        ans = 0;
        for(int i=1; i<=m; i++)
        {
            for(int j=1; j<=n; j++)
            {
                if(a[i][j] == 0)continue;
                ans += 1;///最上层的一个;
                for(int k=0; k<4; k++)
                {
                    int x = i+dir[k][0];
                    int y = j+dir[k][1];
                    ans += max(0, a[i][j] - a[x][y]);
                }
            }
        }
        printf("%I64d\n", ans);
    }
    return 0;
}

时间: 2024-08-06 22:39:16

House Building---hdu5538(求表面积水题)的相关文章

HDU 4667 Building Fence(求凸包的周长)

A - Building Fence Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u Submit Status Description Long long ago, there is a famous farmer named John. He owns a big farm and many cows. There are two kinds of cows on his farm, o

POJ 1861 Network (Kruskal求MST模板题)

Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 14103   Accepted: 5528   Special Judge Description Andrew is working as system administrator and is planning to establish a new network in his company. There will be N hubs in the c

?HDU 2818 Building Block 求大神讲解 (并查集)

#include <stdio.h> #include <iostream> using namespace std; int ff[30005];//ff[x]表示x的父节点 int high[30005]; int low[30005]; void ii(int n) //初始化 { int i; for(i=0;i<=n;i++) //从1开始也是错误的 { ff[i]=i; low[i] = 0; high[i] = 1; } } int dd(int x) //带路

题目1046:求最大值---------------此题较为水,但是仍然有需要注意的地方,原来可以这么输入!!!!

此题,无需输入N,只是简单的输入是个数字, 刚开始的时候, WA的代码: #include<iostream> using namespace std; int main() { int tem; int max=0; while(1) { for (int i=0;i<10;i++) { cin>>tem; if (max<tem) max=tem; } cout<<"max="<<max<<endl; } re

poj1144 tarjan求割点 裸题

Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11684   Accepted: 5422 Description A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N

51nod 2006 飞行员配对(二分图最大匹配) 裸匈牙利算法 求二分图最大匹配题

题目: 题目已经说了是最大二分匹配题, 查了一下最大二分匹配题有两种解法, 匈牙利算法和网络流. 看了一下觉得匈牙利算法更好理解, 然后我照着小红书模板打了一遍就过了. 匈牙利算法:先试着把没用过的左边的点和没用过的右边的点连起来, 如果遇到一个点已经连过就试着把原来的拆掉 把现在这条线连起来看能不能多连上一条线. 总结来说就是试和拆,试的过程很简单,拆的过程由于使用递归写的,很复杂.很难讲清楚,只能看代码自己理会. 代码(有注释): #include <bits\stdc++.h> usin

poj1144Network (求割点模板题)

题目连接 题意:给出一个无向图,求出割点的个数 code: #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <vector> #define maxn 100005 using namespace std; vector<int> G[maxn]; int dfn[maxn],vis[maxn],low[max

luogu P4238 多项式求逆 (模板题、FFT)

手动博客搬家: 本文发表于20181125 13:21:46, 原地址https://blog.csdn.net/suncongbo/article/details/84485718 题目链接: https://www.luogu.org/problemnew/show/P4238 题意: 给定\(n\)次多项式\(A(x)\), 求\(n\)次多项式\(B(x)\)满足\(B(x)A(x)\equiv 1(\mod x^n)\) 题解: DFT,每个数对\(998244353\)求逆元.IDF

hdu 2161 Primes 筛法求素数 大水题

Primes Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7659    Accepted Submission(s): 3130 Problem Description Write a program to read in a list of integers and determine whether or not each n