zoukankan      html  css  js  c++  java
  • hdu 5538(水)

    Input
    The first line contains an integer T indicating the total number of test cases.
    First line of each test case is a line with two integers n,m.
    The n lines that follow describe the array of Nyanko-san's blueprint, the i-th of these lines has m integers ci,1,ci,2,...,ci,m, separated by a single space.

    1T50
    1n,m50
    0ci,j1000
     
    Output
    For each test case, please output the number of glass units you need to collect to meet Nyanko-san's requirement in one line.
     
    Sample Input
    2 3 3 1 0 0 3 1 2 1 1 0 3 3 1 0 1 0 0 0 1 0 1
     
    Sample Output
    30 20


    题意:给你n*m的地方,每个点有一个数组x代表这的高度,求这个立体的表面积

    思路:求出顶部面积,在计算每个柱子比周围柱子高多少即可


    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <queue>
    #include <vector>
    #include <algorithm>
    #include <functional>
    typedef long long ll;
    using namespace std;
    
    int tmap[55][55];
    int dir[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
    
    int main()
    {
        int T,n,m;
        scanf("%d",&T);
        while(T--)
        {
            ll ans = 0;
            scanf("%d%d",&n,&m);
            memset(tmap,0,sizeof(tmap));
            for(int i = 1; i <= n; i ++)
                for(int j = 1; j <= m; j++)
                {
                    scanf("%d",&tmap[i][j]);
                    if(tmap[i][j] > 0)
                        ans ++;
                }
            for(int i = 1; i <= n; i ++)
                for(int j = 1; j <= m; j++)
                {
                    for(int k = 0;k < 4;k++)
                    {
                        int tx = i+dir[k][0];
                        int ty = j+dir[k][1];
                        if(tmap[i][j] > tmap[tx][ty])
                            ans += tmap[i][j] - tmap[tx][ty];
                    }
                }
                printf("%lld
    ",ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    C语言基础:C语言结构体(2)
    C语言基础:C语言结构体(1)
    C语言基础:C语言变量类型
    开源魔兽服务端代码托管地址大全
    新浪微博_第三期整理
    UITextField特性整理
    Xcode快捷键整理
    sleep和wait区别
    IOS7新特性-AVSpeechSynthesisVoice
    【OBJC类扩展之MD5加密】NSString+MD5
  • 原文地址:https://www.cnblogs.com/Przz/p/5409690.html
Copyright © 2011-2022 走看看