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. 2014 Super Training #3 H Tmutarakan Exams --容斥原理

    原题: URAL 1091  http://acm.timus.ru/problem.aspx?space=1&num=1091 题意:要求找出K个不同的数字使他们有一个大于1的公约数,且所有 ...

  2. Mango DS Training #48 ---线段树2 解题手记

    Training address: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=38966#overview A.Count Color ...

  3. POJ 2891 Strange Way to Express Integers【扩展欧几里德】【模线性方程组】

    求解方程组 X%m1=r1 X%m2=r2 .... X%mn=rn 首先看下两个式子的情况 X%m1=r1 X%m2=r2 联立可得 m1*x+m2*y=r2-r1 用ex_gcd求得一个特解x' ...

  4. uGUI练习(五) Draggable Object

    练习目标 学习制作一个可拖动的UI 一.步骤 监听UI的Drag事件,需要我们写一点点的代码. 1.创建一个Panel ,设置size为(100,100) 2.创建DraggableObjectSce ...

  5. android app多渠道分发打包

    1.  美团多渠道包的方法论 1) maven编译多次 2) apktool一次包,解开重新打  (个人倾向于这个) 3) http://tech.meituan.com/mt-apk-packagi ...

  6. zepto.js 源码解析

    http://www.runoob.com/w3cnote/zepto-js-source-analysis.html Zepto是一个轻量级的针对现代高级浏览器的JavaScript库, 它与jqu ...

  7. Gvim使用

    VIM删除空白行 命令:g/^\s*$/d :g 代表在全文档范围内 ^代表行的开始 \s*代表空白字符 &代表行的结束 d代表删除 用//将3段代码隔开

  8. 22Mybatis_订单商品数据模型_多对多查询以及对多对多查询的总结

    之前讲了一对一,一对多查询,这篇文章讲的是多对多. 先给出需求:查询用户及用户购买商品信息. 我们由之前的文章知道,这个需求是多对多的. 还是那个终止我们的mybatis所做的不管是之前的一对一还是一 ...

  9. 08SpringMvc_(1)继承AbstractCommandController的Action[能够以实体的形式,收集客户端参数].(2)日期转换器和编码过滤器

    上一篇文章说过要介绍两个控制器.这篇文章就介绍第二个控制器AbstractCommandController(这个类已经快要被废弃了,有更好的代替者,但还是要好好学这个类).这个控制器的额作用是为了收 ...

  10. .NET 常见的偏门问题

    1.空格 一般情况下," " 的空格可能被过滤掉,在中文输入法中也同样. 有的人会使用2次空格,但是还是无法达到目的. 实现方法:" "的空格,这不是使用2次空 ...