zoukankan      html  css  js  c++  java
  • HDU-4925 Apple Tree

                   http://acm.hdu.edu.cn/showproblem.php?pid=4925

                       Apple Tree

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
    Total Submission(s): 120    Accepted Submission(s): 82


    Problem Description
    I’ve bought an orchard and decide to plant some apple trees on it. The orchard seems like an N * M two-dimensional map. In each grid, I can either plant an apple tree to get one apple or fertilize the soil to speed up its neighbors’ production. When a grid is fertilized, the grid itself doesn’t produce apples but the number of apples of its four neighbor trees will double (if it exists). For example, an apple tree locates on (x, y), and (x - 1, y), (x, y - 1) are fertilized while (x + 1, y), (x, y + 1) are not, then I can get four apples from (x, y). Now, I am wondering how many apples I can get at most in the whole orchard?
     
    Input
    The input contains multiple test cases. The number of test cases T (T<=100) occurs in the first line of input.
    For each test case, two integers N, M (1<=N, M<=100) are given in a line, which denote the size of the map.
     
    Output
    For each test case, you should output the maximum number of apples I can obtain.
     
    Sample Input
    2
    2 2
    3 3
     
    Sample Output
    8
    32
     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 using namespace std;
     5  int n;
     6  int main()
     7 {
     8    int n,m,map[200][200],i,j,t;
     9      scanf("%d",&t);
    10     while(t--)
    11     {
    12         scanf("%d%d",&n,&m);
    13         memset(map,0,sizeof(map));
    14       for(i=1;i<=n;i++)
    15       {
    16         for(j=1;j<=m;j++)
    17         {
    18             map[i][j]=-1;
    19             if((i%2==1)&&(j%2==1))
    20                  map[i][j]=1;
    21             if((i%2==0)&&(j%2==0))
    22                 map[i][j]=1;
    23          }
    24       }
    25 
    26          int a,b;
    27          for(i=1;i<=n;i++)
    28          for(j=1;j<=m;j++)
    29          {
    30              if(map[i][j]==1)
    31                {
    32                   if(map[i-1][j]==-1&&i-1>=1)
    33                        {
    34                            map[i][j]*=2;
    35                         
    36                        }
    37                   if(map[i][j-1]==-1&&j-1>=1)
    38                        {
    39                            map[i][j]*=2;
    40                     
    41                        }
    42                   if(map[i+1][j]==-1&&i+1<=n)
    43                   {
    44                       map[i][j]*=2;
    45                       
    46                   }
    47 
    48                    if(map[i][j+1]==-1&&j+1<=m)
    49                        {
    50                            map[i][j]*=2;
    51                           
    52                        }
    53                }
    54          }
    55          int ans=0;
    56          for(i=1;i<=n;i++)
    57            for(j=1;j<=m;j++)
    58            {
    59                if(map[i][j]!=-1)
    60                ans+=map[i][j];
    61            }
    62 
    63         printf("%d
    ",ans);
    64 
    65     }
    66     return 0;
    67 }
     
    Source
     
  • 相关阅读:
    CentOS 添加sudo 用户
    CentOS 7 Hostname
    Java 两线程交替打印奇偶数(一)
    Angular2 Forms
    Built-in Components
    How Angular Works
    数字签名算法
    不对称加密算法
    对称加密算法
    消息摘要算法
  • 原文地址:https://www.cnblogs.com/cancangood/p/3897896.html
Copyright © 2011-2022 走看看