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. webstorm 如何配置git

    2016-09-22 15:00:25 补充js 操作后 发现工具自动生成了两个文件,如果提交到git上 会造成不必要的麻烦,看看怎么去掉产生这个的原因吧! 去掉对应的监听:http://fronte ...

  2. PHP一个最简单的CMS内容管理系统

    博客是一般程序员的入手戏,写得好写不好,有没有兴趣,逻辑性够不够都从这个里面入手 我现在摒弃前台.重点讲解下如何开发一个简单的CMS系统所需要的步骤: 1.清楚流程 1--------登录后台 2-- ...

  3. Java-Android 之出滚动条和卷轴页面

    <?xml version="1.0" encoding="utf-8"?> <HorizontalScrollView xmlns:andr ...

  4. 如何快速的将Centos6.7快速升级3.10.9

    参考文档:http://www.xiexianbin.cn/linux/2015/10/15/quickly-upgrade-centos6.5-kernel-from-2.6.32-to-3.10. ...

  5. jQuery无刷新上传学习心得

    记得刚离开大学,进入目前这家公司不到一个月时,有一位前辈给我们当时的新人讲了下JS无刷新上传的相关知识. 在此之前,一直都是在使用C#提供的服务器上传控件FileUpload,但是每次使用时,都会刷新 ...

  6. 反射(学习整理)----Class类和加载器ClassLoader类的整理

    1.学习反射的时整理的笔记!Class类和ClassLoader类的简单介绍 反射机制中的Class Class内部到底有什么呢?看下图! 代码: Class cls=Person.class; .C ...

  7. ScheduleThreadPoolExecutor源码分析

    ScheduleThreadPoolExecutor源码分析(一) Java中ScheduleThreadPoolExecutor主要用于执行延迟任务或者按照一定的频率执行任务.其中scheduleA ...

  8. 学习protobuf

    一.认识Protobuf ref:http://blog.csdn.net/program_think/article/details/4229773摘要:1. protobuf是一个开源项目.2. ...

  9. [Introduction to programming in Java 笔记] 1.3.8 Gambler's ruin simulation 赌徒破产模拟

    赌徒赢得机会有多大? public class Gambler { public static void main(String[] args) { // Run T experiments that ...

  10. marquee标签制作轮播图

    http://qy-0824.blog.163.com/blog/static/725075422011214142226/ 缺点是仅能控制轮播的速度.鼠标悬停暂停等,并不能给其指定链接.触摸滑动.分 ...