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

法二。

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

代码:

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

法三。

通过分析推出公式(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>)
{
if(y==)
s=(x-)*;
else
s=(x-)**(y-);
}
else
{
if(y==)
s=;
else
s=*(y-);
}
printf("%d\n",s);
}
return ;
}

  

【HDU 4925】BUPT 2015 newbie practice #2 div2-C-HDU 4925 Apple Tree的更多相关文章

  1. 【CodeForces 312B】BUPT 2015 newbie practice #3A Archer

    题 SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the targ ...

  2. 【CodeForces 605A】BUPT 2015 newbie practice #2 div2-E - Sorting Railway Cars

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/E Description An infinitely lon ...

  3. 【UVALive 3905】BUPT 2015 newbie practice #2 div2-D-3905 - Meteor

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/D The famous Korean internet co ...

  4. 【UVA 401】BUPT 2015 newbie practice #2 div2-B-Palindromes

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/B A regular palindrome is a str ...

  5. 【UVA 11078】BUPT 2015 newbie practice #2 div2-A -Open Credit System

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/A In an open credit system, the ...

  6. 【最大流】ECNA 2015 F Transportation Delegation (Codeforces GYM 100825)

    题目链接: http://codeforces.com/gym/100825 题目大意: N(N<=600)个点,每个点有个名字Si,R(R<=200)个生产商在R个点上,F(F<= ...

  7. 【宽搜】ECNA 2015 D Rings (Codeforces GYM 100825)

    题目链接: http://codeforces.com/gym/100825 题目大意: 给你一张N*N(N<=100)的图表示一个树桩,'T'为年轮,'.'为空,求每个'T'属于哪一圈年轮,空 ...

  8. 【宽搜】ECNA 2015 E Squawk Virus (Codeforces GYM 100825)

    题目链接: http://codeforces.com/gym/100825 题目大意: N个点M条无向边,(N<=100,M<=N(N-1)/2),起始感染源S,时间T(T<10) ...

  9. 【VSTS 日志】TFS 2015 Update 1 发布 – Git和TFVC代码库可以混合使用了

    Visual Studio Team Foundation Server 2015 Update 1已经发布了. 这是 Team Foundation Server (TFS) 的最新版本,是 Mic ...

随机推荐

  1. css3中的多列布局columns详解

    columns语法:columns:[ column-width ] || [ column-count ]设置或检索对象的列数和每列的宽度 其中:[ column-width ]:设置或检索对象每列 ...

  2. 2014-2015 Codeforces Trainings Season 2 Episode 7 G Gophers --线段树

    题意: 有n个地鼠,m个CD碟,每个CD碟有一个影响范围,范围内的地鼠都会被吵到,每次有一个操作就是移动CD碟,然后求每次被影响的地鼠有多少只. 解法: 线段树做.我们只关注地鼠有没有被吵到就可以了, ...

  3. Codeforces Round #257(Div.2) D Jzzhu and Cities --SPFA

    题意:n个城市,中间有m条道路(双向),再给出k条铁路,铁路直接从点1到点v,现在要拆掉一些铁路,在保证不影响每个点的最短距离(距离1)不变的情况下,问最多能删除多少条铁路 分析:先求一次最短路,铁路 ...

  4. java11-1 最常见的类 String类

    字符串:就是由多个字符组成的一串数据.也可以看成是一个字符数组. 通过查看API,可以知道 A:字符串字面值"abc"也可以看成是一个字符串对象. B:字符串是常量,一旦被赋值,就 ...

  5. ASP.NET错误处理的方式(总结)

    转载至: http://www.cnblogs.com/chinhr/archive/2007/06/26/795947.html ASP.NET错误处理的方式(整理&总结)英文文章研究:ht ...

  6. OpenGL2.0及以上版本中glm,glut,glew,glfw,mesa等部件的关系

    OpenGL2.0及以上版本中gl,glut,glew,glfw,mesa等部件的关系 一.OpenGL OpenGL函数库相关的API有核心库(gl),实用库(glu),辅助库(aux).实用工具库 ...

  7. python中class 的一行式构造器

    好处:避免类初始化时大量重复的赋值语句 用到了魔法__dict__ # 一行式构造器 class Test(): # 初始化 def __init__(self, a, b, c=2, d=3, e= ...

  8. 一款Android开源的下拉刷新动画

    无意间在GitHub看到的,就Down了下来.但是作者是用AndroidStudio开发的,这边移动Eclipse供小伙伴们下载使用. 截图 这么好的东西因为字数不够不让分享,得了,贴段代码吧 pac ...

  9. Java集合---HashSet的源码分析

    一.  HashSet概述: HashSet实现Set接口,由哈希表(实际上是一个HashMap实例)支持.它不保证set 的迭代顺序:特别是它不保证该顺序恒久不变.此类允许使用null元素. 二.  ...

  10. mysql5.7.12直接解压zip包,安装过程

    MySQL-5.7.12-winx64.zip解压安装方式 1.解压文件到你想要安装的位置.     本人是直接解压到E盘. 2.配置环境变量,在path中放入:E:\mysql-5.7.12-win ...