【HDOJ5538】House Building(計算幾何)

來源:互聯網
上載者:User

標籤:code   long   class   size   ems   思路   col   hdoj   set   

題意:給定一個n*m的方陣,第i行第j列的高度為a[i][j],問除了下底面之外其餘五面的總表面積

n<=50,0<=a[i][j]<=1000

思路:隊友寫的,抱大腿

考慮當前方格比周圍四格高多少即可

 1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 #define LL long long   5 const int maxn=55; 6 int a[maxn][maxn]; 7 int dx[4]={1,0,-1,0}; 8 int dy[4]={0,1,0,-1}; 9 int main()10 {11     int T;12     scanf("%d",&T);13     while(T--)14     {15         int n,m;16         memset(a,0,sizeof(a));17         scanf("%d%d",&n,&m);18         for(int i=1;i<=n;i++)19             for(int j=1;j<=m;j++)20                 scanf("%d",&a[i][j]);21         int sum=0;22         for(int i=1;i<=n;i++)23             for(int j=1;j<=m;j++)24             {25                 if(!a[i][j])26                     continue;27                 sum++;28                 for(int k=0;k<4;k++)29                 {30                     int x=dx[k]+i;31                     int y=dy[k]+j;32                     if(a[x][y]<a[i][j])33                         sum+=a[i][j]-a[x][y];34                 }35             }36         printf("%d\n",sum);37     }38 }

 

【HDOJ5538】House Building(計算幾何)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.