zoukankan      html  css  js  c++  java
  • HDU 4925 Apple Tree(模拟题)

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

    解题报告:给你n*m的土地,现在对每一块土地有两种操作,最多只能在每块土地上进行两种操作,第一种是种苹果树操作,第二种是施肥操作,种苹果树操作可以使得该块地

    长出一个苹果,施肥操作可以使得与这块土地相邻的土地的苹果产量变为原来的两倍,问可以得到的最多的苹果数量是多少?

    例如一个4*4的土地,用1表示在该土地上做第一种操作,0表示在该土地上做第二种操作,可以得到最多苹果的操作如下:

    0 1 0 1

    1 0 1 0

    0 1 0 1

    1 0 1 0

    也就是说对于第i行第j列,如果(i + j)为奇数的话就种树,其它的土地都施肥。

    注意要对1 * 1的土地加特判。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<algorithm>
     5 using namespace std;
     6 const int maxn = 100+5;
     7 int map[maxn][maxn];
     8 int _x[4] = {-1,0,1,0};
     9 int _y[4] = {0,1,0,-1};
    10 int main()
    11 {
    12     int T,n,m;
    13     scanf("%d",&T);
    14     while(T--)
    15     {
    16         scanf("%d%d",&n,&m);
    17         if(n == 1 && m == 1)
    18         {
    19             printf("1
    ");
    20             continue;
    21         }
    22         memset(map,0,sizeof(map));
    23         for(int i = 1;i <= n;++i)
    24         for(int j = 1;j <= m;++j)
    25         if((i + j) & 1)
    26         map[i][j] = 1;
    27         for(int i = 1;i <= n;++i)
    28         for(int j = 1;j <= m;++j)
    29         if(!map[i][j])
    30         for(int k = 0;k <  4;++k)
    31         {
    32             int x = i + _x[k];
    33             int y = j + _y[k];
    34             if(x >= 1 && x <= n && y >= 1 && y <= m)
    35             map[x][y] *= 2;
    36         }
    37         int ans = 0;
    38         for(int i = 1;i <= n;++i)
    39         for(int j = 1;j <= m;++j)
    40         ans += map[i][j];
    41         printf("%d
    ",ans);
    42     }
    43     return 0;
    44 }
    View Code
  • 相关阅读:
    虚方法(virtual)和抽象方法(abstract)的区别
    IT社区
    C#中动态加载和卸载DLL
    应用程序体系结构
    Enterprise Architect 7.0入门教程
    jQuery插件开发基础1
    asp.net页面事件执行顺序
    codesmith4.1破解版
    在Web.config配置文件中自定义配置节点
    小巧实用的节拍器软件FineMetronome介绍 原创
  • 原文地址:https://www.cnblogs.com/xiaxiaosheng/p/3898016.html
Copyright © 2011-2022 走看看