题目链接: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): 188    Accepted Submission(s): 129

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
 
Source
 
Recommend
 

Statistic | Submit | Discuss | Note

签道题,没啥好说的,黑白染色的方法是最优的,特判1*1的情况

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define CLR(A) memset(A,0,sizeof(A))
int A[110][110];
int main(){
int T,m,n;
cin>>T;
while(T--){
cin>>n>>m;
if(n==1 && m==1){
cout<<1<<endl;
continue;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
A[i][j]=1;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
if(A[i][j]==1){
A[i-1][j]<<=1;
A[i+1][j]<<=1;
A[i][j-1]<<=1;
A[i][j+1]<<=1;
}
}
long long sum=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
if(A[i][j]!=1){
sum+=A[i][j];
}
}
cout<<sum<<endl;
}
return 0;
}

hdu 4925 Apple Tree--2014 Multi-University Training Contest 6的更多相关文章

  1. HDU 4925 Apple Tree(推理)

    HDU 4925 Apple Tree 题目链接 题意:给一个m*n矩阵种树,每一个位置能够选择种树或者施肥,假设种上去的位置就不能施肥,假设施肥则能让周围果树产量乘2.问最大收益 思路:推理得到肯定 ...

  2. HDU 4925 Apple Tree (瞎搞)

    找到规律,各一个种一棵树.或者施肥.先施肥,先种树一样. Apple Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 2621 ...

  3. 2014多校第六场 1005 || HDU 4925 Apple Tree

    题目链接 题意 : 给你一块n×m的矩阵,每一个格子可以施肥或者是种苹果,种一颗苹果可以得到一个苹果,但是如果你在一个格子上施了肥,那么所有与该格子相邻(指上下左右)的有苹果树的地方最后得到的苹果是两 ...

  4. HDU 4925 Apple Tree(模拟题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 解题报告:给你n*m的土地,现在对每一块土地有两种操作,最多只能在每块土地上进行两种操作,第一种 ...

  5. hdoj 4925 Apple tree 【最小割】

    题目:pid=4925">hdoj 4925 Apple tree 来源:2014 Multi-University Training Contest 6 题意:给出一个矩阵,然后每一 ...

  6. 【HDU 4925】BUPT 2015 newbie practice #2 div2-C-HDU 4925 Apple Tree

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/C Description I’ve bought an or ...

  7. HDU 6091 - Rikka with Match | 2017 Multi-University Training Contest 5

    思路来自 某FXXL 不过复杂度咋算的.. /* HDU 6091 - Rikka with Match [ 树形DP ] | 2017 Multi-University Training Conte ...

  8. HDU 6125 - Free from square | 2017 Multi-University Training Contest 7

    思路来自这里 - - /* HDU 6125 - Free from square [ 分组,状压,DP ] | 2017 Multi-University Training Contest 7 题意 ...

  9. HDU 6129 - Just do it | 2017 Multi-University Training Contest 7

    比赛时脑子一直想着按位卷积... 按题解的思路: /* HDU 6129 - Just do it [ 规律,组合数 ] | 2017 Multi-University Training Contes ...

随机推荐

  1. ixcache的蜜汁突发故障

    公元2018年 7月29日 晚上21点整,我司一直正常运行的ixcache线路异常断开. ??? 公司业务包含提供互联网接入服务,所以这个现象将会导致用户上网体验变差,网速变慢,看视频的速度下降等等, ...

  2. Objective-C-------(1)创建并使用对象

    #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...

  3. C第12章-----堆

    #include <stdio.h> #include <stdlib.h> //声明Person结构 //struct Person{ //    float heightI ...

  4. Task(TPL)简单的实现Winform(WPF)异步

    很多时候,我们要实现Winform异步操作,你可以用传统的方法,但个人感觉代码不好理解,而且使用真有点不舒服.也可以用Task来实现,Task(.net4.0新添加的对象)其实就是对线程池线程的一个封 ...

  5. iframe in ipad safari

    http://developer.apple.com/library/safari/#documentation/appleapplications/reference/safariwebconten ...

  6. jQuery+ajax城市联动

    分享一下自己最近写的城市联动.技术使用ajax+jQuery实现. 首先请看前台的javascript代码. 以下是连个实现异步加载的方法. <script type="text/ja ...

  7. python011 Python3 字典

    Python3 字典字典是另一种可变容器模型,且可存储任意类型对象.字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包括在花括号({})中 ,格式如 ...

  8. zoj 1295 Reverse Text

    Reverse Text Time Limit: 2 Seconds      Memory Limit: 65536 KB In most languages, text is written fr ...

  9. Go函数学习

    package main import ( "fmt" "reflect" "runtime" "math" ) //函 ...

  10. 【Zeller公式计算星期几】HDU 6112 今夕何夕

    acm.hdu.edu.cn/showproblem.php?pid=6112 [思路] 公式计算即可,注意特判2月29号 Zeller公式里,计算出的week不能直接模7,要保证week是正数 [A ...