http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/C

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

题意:给你n×m的格子,每个格子你可以选择给1,或者使它上下左右(如果有)的数字乘2,你对每个格子操作的先后顺序是自由的,求所有格子数字总和的最大值。

t组(小于100)数据,n和m(1到100)

题解:要使总和最大,那就每隔一个格子给1,使得每个给1的格子周围都是乘2的格子,这样它就乘了最多次2,比如3行4列

1 0 1 0

0 1 0 1

1 0 1 0

这里0表示使周围的乘2,我们的顺序是先给1,再乘2,于是总和是4+8+16+8+4+8=48

法一。

模拟这些格子,根据n和m,构造出上述的01二维数组,再对每个格子判断周围几个0,然后乘几次2,累加答案

代码:

#include<cstdio>
#include<cstring>int ma[105][105];
int main()
{int n,m,t,k,ans,u,h;int ma[105][105];scanf("%d",&t);while(t--){memset(ma,0,sizeof(ma));ans=0;k=0;scanf("%d%d",&n,&m);for(int i=0; i<n; i++){for(int j=0+k; j<m; j+=2)ma[i][j]=1;//设置它为1k=!k;}for(int i=0; i<n; i++){for(int j=0; j<m; j++){if(ma[i][j]){h=1;u=0;if(i-1>=0)if(!ma[i-1][j])u++;//如果为0,代表乘2if(i+1<n)if(!ma[i+1][j])u++;if(j-1>=0)if(!ma[i][j-1])u++;if(j+1<m)if(!ma[i][j+1])u++;for(int l=1; l<=u; l++)h*=2;ans+=h;}}}printf("%d\n",ans);}return 0;}

法二。

如果行列数之和为奇数,则给1,并且使它周围为乘2,则这个1就要乘几次2了,根据是否在边缘,判断乘几次2,累加答案

代码:

//code from lyt
#include<cstdio>
using namespace std;
int T;
int n,m;
long long ans=0;
long long now=0;
int main()
{scanf("%d",&T);while(T){scanf("%d%d",&n,&m);ans=0;for(int i=1; i<=n; i++){for(int j=1; j<=m; j++){if((i+j)&1){now=1;if(i>1)now<<=1;if(j>1)now<<=1;if(i<n)now<<=1;if(j<m)now<<=1;ans+=now;}}}printf("%lld\n",ans);T--;}return 0;
}

法三。

通过分析推出公式(x表示n,y表示m)

ans=1,当x=1,y=1;

ans=2*(y-1),当x=1,y>1;

ans=(x-1)*2,当x>1,y=1;

ans=(x-1)*8*(y-1),当x>1,y>1;

具体怎么分析推出的,...不详

代码:

//code from zdh
#include<stdio.h>
int T,x,y,s;
int main()
{scanf("%d",&T);while(T--){scanf("%d%d",&x,&y);if(x>1){if(y==1)s=(x-1)*2;elses=(x-1)*8*(y-1);}else{if(y==1)s=1;elses=2*(y-1);}printf("%d\n",s);}return 0;
}

  

【HDU 4925】BUPT 2015 newbie practice #2 div2-C-HDU 4925 Apple Tree相关推荐

  1. 【论文阅读】Mastering the game of Go with deep neural networks and tree search

    [论文阅读]Mastering the game of Go with deep neural networks and tree search 1 本文解决了什么问题? 在所有的 完全信息博弈 中, ...

  2. 【文章阅读】BN(2015)理解Batch Normalization批标准化

    Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift Brief 该 ...

  3. 【论文学习】ASVspoof 2015 the First Automatic Speaker Verification Spoofing and Countermeasures Challenge

    <ASVspoof 2015: the First Automatic Speaker Verification Spoofing and Countermeasures Challenge&g ...

  4. 【动态规划】【数位DP】[PA 2015]Rownanie

    题目描述 对于一个正整数 n,定义 f(n) 为它十进制下每一位数字的平 方的和. 现在给定三个正整数 k,a,b,请求出满足 a≤n≤b 且 k×f(n) = n 的 n 的个数. 1≤k,a,b≤ ...

  5. 记账凭证php源码,【FICO系列】SAP FI模块-记账凭证FB01的BAPI

    公众号:SAP Technical 本文作者:matinal 前言部分 大家可以关注我的公众号,公众号里的排版更好,阅读更舒适. 正文部分 FI模块记账凭证FB01的BAPI - POSTING_IN ...

  6. grade项目导入新external libraries_【易推荐】德意志银行学院中国项目启动

    展翅高飞 开阔眼界 探索新的机遇总会令人振奋不已.德意志银行集团(以下简称德意志银行或德银)举办了"德意志银行学院"项目(DB Academy,以下简称"德银学院&quo ...

  7. 【活动预告】说说对 Coding 新一年的期许, Filco 蓝牙无线机械键盘等你拿!

    最近流行着这么一句话:程序猿,多用云端工具开发,父母想你早点回家. 于是,Coding.net 老大也 p 一个 看完此图,工程师们感到深深 伐 ! 开 ! 心 ! 于是心疼程序猿的女神说 : 休息一 ...

  8. 【Alpha版本】冲刺阶段 - Day7 - 靠泊

    Alpha:指集成了主要功能的第一个试用版本.在这个版本中有些小功能并未实现.事实上很多软件的 Alpha 版本只是在内部使用.给外部用户使用的 Alpha 版本会起一个比较美妙的名字,例如,技术预览 ...

  9. 大数加法【HDU 1002】

    大数加法模板 一般的加法只要int类型的两数直接相加即可,大一点的数可以设为long long类型,而超过长整型的数则属于大数问题了,大数加法其实也比较简单,利用数组实现就可以啦: 主要思想如下: ( ...

最新文章

  1. makefile:2: *** 遗漏分隔符 。 停止
  2. Linux内核路由表介绍及相关函数
  3. 我的特长是计算机VF编程,2016计算机二级考试VF模拟题及答案
  4. D3 selectselectAll
  5. MySQL配置优化选项
  6. 浅谈5类过零检测电路
  7. 综合计算机工时,计算机辅助工时定额制定与管理系统的研究与开发
  8. uib-datepicker-popup使用
  9. Towards End-to-End Prosody Transfer for Expressive Speech Synthesis with Tacotron
  10. 通过u盘启动计算机使用ghost安装系统步骤,详细教您如何使用u盘启动盘手动ghost备份系统...
  11. leetcode加一
  12. 数据结构(二)——栈及实现、括号匹配
  13. 让手机变成电脑摄像头
  14. 关于U盘存储大量小容量文件速度慢的解释(摘抄)
  15. android 隐私泄露 路径,一种Android应用隐私泄露漏洞检测方法与流程
  16. oracle 中的nvl函数使用
  17. 免费的 ChatGPT镜像网站
  18. Java 基本数据类型(八种基本数据类型)
  19. Flutter淘宝App之首页聚划算倒计时的实现
  20. BOW 原理及代码解析

热门文章

  1. robotac属于a类还是b类_所得税A类和B类的区别,什么样的属于B类??
  2. JAVA集合Set之HashSet详解_Java基础———集合之HashSet详解
  3. easyUI 鼠标悬浮 和截取
  4. python中︿是什么意思_Python learning notes-0003-注释、变量、简单类型、运算符,学习,笔记...
  5. r语言 求几个数的最小公倍数_【微课】北师大版五年级数学上册第五单元8找最小公倍数...
  6. AngularJs的基础——$http请求数据
  7. 六部工坊ros启智机器人定点导航技术_【展品抢鲜看】程天科技外骨骼机器人亮相峰会,让每个人享受机器人的服务!...
  8. html重复div绘制,[DIV+CSS]绘制2重交叉表_html/css_WEB-ITnose
  9. ffmpeg命令_温故知新:ffmpeg操作《天空之城》。窗口党勿入,都是指令!
  10. pear php有什么用?,php – PEAR和PEAR2有什么区别?