zoukankan      html  css  js  c++  java
  • hdu 4925 黑白格

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

    给定一个N*M的网格,对于每个格子可以选择种树和施肥,默认一个苹果树收获1个苹果,在一个位置施肥的话,周围四个格子如果有种树,那么产量加倍。为最大产量。

    黑白格方法最优,模拟即可

    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <cstring>
    #include <string>
    #include <queue>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    #define RD(x) scanf("%d",&x)
    #define RD2(x,y) scanf("%d%d",&x,&y)
    #define clr0(x) memset(x,0,sizeof(x))
    typedef long long LL;
    
    int n,m;
    int f[] = {1,2,4,8,16};
    bool a[200][200];
    
    void work() {
        int ans = 0;
        for (int i = 0; i <= n + 1; i++)
            for (int j = 0; j <= m + 1; j++)
                a[i][j] = false;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                if ((i + j) % 2 == 1)
                    a[i][j] = true;
    
        for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            if (a[i][j] == true)
                continue;
            int cnt = 0;
            if (a[i - 1][j])
                cnt++;
            if (a[i + 1][j])
                cnt++;
            if (a[i][j - 1])
                cnt++;
            if (a[i][j + 1])
                cnt++;
            ans += f[cnt];
        }
        printf("%d
    ",ans);
        return;
    }
    
    int main(){
        int _;
        RD(_);
        while(_--){
            RD2(n,m);
            work();
        }
        return 0;
    }


  • 相关阅读:
    mysql 统计数据库基本资源sql
    java ffmpeg (Linux)截取视频做封面
    shutil模块
    json模块与pickle模块
    hashlib模块
    sys模块
    os模块
    paramiko模块
    Python reduce() 函数
    瀑布流展示图片
  • 原文地址:https://www.cnblogs.com/zibaohun/p/4046773.html
Copyright © 2011-2022 走看看