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 ...
随机推荐
- 【锋利的jQuery】学习笔记01
第一章 认识jQuery 一.常见的JS库 Prototype 最早的js库之一.把好用JS方法组合,缺点结构松散. Dojo 离线存储API.生成图标组件.矢量图形库.Comet支持.企业级JS库, ...
- 面向报文(UDP)和面向字节流(TCP)的区别
转载:http://blog.csdn.net/wanghaobo920/article/details/11877589 面向报文(UDP)和面向字节流(TCP)的区别 面向报文的传输方式是应用层交 ...
- Sql产生自动增长的编号
USE [DBName]GO/****** Object: StoredProcedure [dbo].[sp_GetNo] Script Date: 10/24/2013 19:26:44 ...
- json解析异常 - net.sf.json.JSONException: java.lang.reflect.InvocationTargetException
注:在项目中, 我使用原生的ajax请求数据的时候, JSONObject没能帮我解析, 当却不给我报错, 我是在junit单元测试中测试的时候, 发现的.发现好多时候, 特别是通过ajax请求, 不 ...
- jsp - 引用 jar包.
在jsp中使用不同的方式引用jar,准备的工作也不同.我接触过的有两种:1)直接在jsp页面中引用;2)在src下的java类中引用,然后在jsp中调用java类. 1)直接引用:可以将jar包丢到W ...
- mvc5 + ef6 + autofac搭建项目(三)
前面已经基本完成了框架的搭建,后面就是实现了,后面主要说下前端的东西bootstrap的使用和相关插件. 看图: 实现比较简单,在主页面只引入共用部分的 js等相关包,毕竟不是所有页面都需要列表以及其 ...
- iBATIS缓存cacheModel属性浅析
iBATIS缓存cacheModel属性的应用使得在Mapped Statement中缓存常用的数据,那么本文将会给你介绍iBATIS缓存cacheModel属性的信息. AD:2013云计算架构师峰 ...
- [转载] java中byte数组与int,long,short间的转换
文章转载自http://blog.csdn.net/leetcworks/article/details/7390731 package com.util; /** * * <ul> * ...
- 【JAVA集合】HashMap源码分析(转载)
原文出处:http://www.cnblogs.com/chenpi/p/5280304.html 以下内容基于jdk1.7.0_79源码: 什么是HashMap 基于哈希表的一个Map接口实现,存储 ...
- Bad owner or permissions on .ssh/config
Bad owner or permissions on $HOME/.ssh/config The ssh with RHEL 4 is a lot more anal about security ...