HDU-4925 Apple Tree
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
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?
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.
number of apples I can obtain.
#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 ;
}
HDU-4925 Apple Tree的更多相关文章
- HDU 4925 Apple Tree(推理)
HDU 4925 Apple Tree 题目链接 题意:给一个m*n矩阵种树,每一个位置能够选择种树或者施肥,假设种上去的位置就不能施肥,假设施肥则能让周围果树产量乘2.问最大收益 思路:推理得到肯定 ...
- HDU 4925 Apple Tree (瞎搞)
找到规律,各一个种一棵树.或者施肥.先施肥,先种树一样. Apple Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 2621 ...
- HDU 4925 Apple Tree(模拟题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 解题报告:给你n*m的土地,现在对每一块土地有两种操作,最多只能在每块土地上进行两种操作,第一种 ...
- 2014多校第六场 1005 || HDU 4925 Apple Tree
题目链接 题意 : 给你一块n×m的矩阵,每一个格子可以施肥或者是种苹果,种一颗苹果可以得到一个苹果,但是如果你在一个格子上施了肥,那么所有与该格子相邻(指上下左右)的有苹果树的地方最后得到的苹果是两 ...
- 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 ...
- hdoj 4925 Apple tree 【最小割】
题目:pid=4925">hdoj 4925 Apple tree 来源:2014 Multi-University Training Contest 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 ...
- HDU 6206 Apple (高精确度+JAVA BigDecimal)
Problem Description Apple is Taotao's favourite fruit. In his backyard, there are three apple trees ...
- POJ 2486 Apple Tree
好抽象的树形DP......... Apple Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6411 Accepte ...
随机推荐
- SqlServer 三级联动、递归表
SqlServer 省市县三级联动 三张表递归合并成一张表sql如下: insert into table2(area_name,area_parent_id) select province,'0' ...
- Javascript 汉字转拼音
调用方式: var pinyin = convert("欢迎光临"); alert(pinyin); 新建JS文件:PYConvert.js,内容如下: var PinYin = ...
- Java SpringMvc+hibernate架构中,调用Oracle中的sp,传递数组参数
一.问题 我们调用数据,大都是可以直接获取表中的数据,或者用复杂点的sql语句组成的.但是,有时候,当这样达不到我们要的全部数据的时候,这时,我们就用到了存储过程[sp],如果sp需要参数是数组的话, ...
- SQL语句like子句中的转义符 [转载]
如果想在SQL LIKE里查询有下划线'_'或是'%'等值的记录,直接写成like 'XXX_XX',则会把'_'当成是like的通配符.SQL里提供了 escape子句来处理这种情况,escape可 ...
- Binary Tree Level Order Traversal II 解题思路
思路: 与Binary Tree Level Order Traversal I 几乎一样.只是最后将结果存放在栈里,然后在栈里再传给向量即可. 再次总结思路: 两个queue,先把第一个放进q1,循 ...
- Photon引擎开发实战(1)——Photon 简介
Photon简介 Photon是一套使用广泛的socket server引擎,服务端底层C++编写,客户端C#编写,跨多平台,收费,效率可观的一款引擎.实用上前有九城游戏(原魔兽世界代理),现在笔者发 ...
- asp.net Linq 实现分组查询
首先我们还是先建立一个person.cs类 public class person { public string name { get; set; } public int age { get; s ...
- winform C#屏幕右下角弹出消息框并自动消失
①弹出信息框后慢慢下降消失 在主窗体中新增按钮重命名为btnShowAndDisappearMessages,在click事件中写如下代码: private void btnShowAndDisapp ...
- ubuntu chm文档阅读
四种方法在Ubuntu下查看CHM文件 来源:http://os.51cto.com/art/201108/287748.htm Ubuntu是一个以桌面应用为主的Linux操作系统,刚开始使用Ubu ...
- WPF DataGrid
前台代码 <DataGrid Name="gv_GetWork" AutoGenerateColumns="False" CanUserSortColum ...