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
 #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int n;
int main()
{
int n,m,map[][],i,j,t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
memset(map,,sizeof(map));
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
map[i][j]=-;
if((i%==)&&(j%==))
map[i][j]=;
if((i%==)&&(j%==))
map[i][j]=;
}
} int a,b;
for(i=;i<=n;i++)
for(j=;j<=m;j++)
{
if(map[i][j]==)
{
if(map[i-][j]==-&&i->=)
{
map[i][j]*=; }
if(map[i][j-]==-&&j->=)
{
map[i][j]*=; }
if(map[i+][j]==-&&i+<=n)
{
map[i][j]*=; } if(map[i][j+]==-&&j+<=m)
{
map[i][j]*=; }
}
}
int ans=;
for(i=;i<=n;i++)
for(j=;j<=m;j++)
{
if(map[i][j]!=-)
ans+=map[i][j];
} printf("%d\n",ans); }
return ;
}
 
Source
 

HDU-4925 Apple Tree的更多相关文章

  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. HDU 4925 Apple Tree(模拟题)

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

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

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

  5. hdu 4925 Apple Tree--2014 Multi-University Training Contest 6

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others ...

  6. hdoj 4925 Apple tree 【最小割】

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

  7. 【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 ...

  8. HDU 6206 Apple (高精确度+JAVA BigDecimal)

    Problem Description Apple is Taotao's favourite fruit. In his backyard, there are three apple trees ...

  9. POJ 2486 Apple Tree

    好抽象的树形DP......... Apple Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6411 Accepte ...

随机推荐

  1. svn出错问题(用户名密码有修改以及资源url改变时)

    用eclipse 同步SVN服务器宛然无法访问了: org.tigris.subversion.javahl.ClientException: RA layer request failed svn: ...

  2. mysql开启函数功能

    输入 show variables like '%func%'; 命令 会看到 log_bin_trust_function_creators 的状态,如果是OFF表示自定义函数功能是关闭的 输入命令 ...

  3. <>跟!=

    这两个是没有区别的,都是不等于

  4. 消息中间件MQ基础理论知识

    欢迎转载,转载请注明出处:http://www.cnblogs.com/lidabnu/p/5723280.html 消息中间件已经流行很长时间,一般情况下,不需要自己来从头研发.设计消息中间件,所以 ...

  5. C语言之分配

    #include "stdio.h" void main() { ] = {,,}; *sizeof(int));//malloc calloc relloc arr2[] = ; ...

  6. C# 基础 知识点

    类型 1.decimal为高精度浮点数,常用于货币计算,然后它不是基本类型,所以性能相对float和double要差. 2.@用于字符串前使转义字符 \  无效,甚至能将回车当作换行符直接赋值给字符串 ...

  7. java中关于static的小知识

    static能够修饰属性和方法.凡是static修饰的方法和属性都是和类的关系较大,都在加载的时候要特殊处理(包括属性和类的优先加载).下面比较下static修饰属性和方法时的区别: 一.修饰属性的时 ...

  8. linux下安装svn(基于编码的方式)

    svn是什么,相信能看到这里的同学应该不会有这个问题了,费话不多说,开始: 1.创建目录 mkdir /home/svn/ 2.获取安装svn所需源文件(svn的官方网址是http://subvers ...

  9. 『重构--改善既有代码的设计』读书笔记----Replace Array with Object

    如果你有一个数组,其中的元素各自代表不同东西,比如你有一个 QList<QString> strList; 其中strList[0]代表选手姓名,strList[1]代表选手家庭住址,很显 ...

  10. jquery roundabout幻灯片插件3d图片切换支持图片旋转切换滚动

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...