HDU 4925 Apple Tree(推理)
HDU 4925 Apple Tree
题意:给一个m*n矩阵种树,每一个位置能够选择种树或者施肥,假设种上去的位置就不能施肥,假设施肥则能让周围果树产量乘2。问最大收益
思路:推理得到肯定是果树和肥料交叉种好,类似国际象棋棋盘,黑的种,白的施肥。因为格子数不多,直接去枚举每一个位置就可以。假设题目格子数多的话。事实上也能够推出公式一步得到答案
代码:
#include <cstdio>
#include <cstring> const int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; int t, n, m; int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
int flag = 1;
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (flag) {
int cnt = 1;
for (int k = 0; k < 4; k++) {
int xx = i + d[k][0];
int yy = j + d[k][1];
if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue;
cnt *= 2;
}
ans += cnt;
}
flag ^= 1;
}
}
printf("%d\n", ans);
}
return 0;
}
HDU 4925 Apple Tree(推理)的更多相关文章
- 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-4925 Apple Tree
http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others) ...
- 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 ...
随机推荐
- Codeforces 810 A.Straight «A»
A. Straight «A» time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- SecureCRT的安装、介绍、简单操作
网上看到一篇名为<SecureCRT的使用方法和技巧(详细使用教程)>的secureCRT教程,可能软件版本与我不一样我安装的是8.1. 原文来源:http://www.jb51.net/ ...
- Ubuntu下安装 Phantomjs
1.安装phantomjs —-下载程序文件 wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x8 ...
- HDU 1556 Color the ball【差分数组裸题/模板】
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一 ...
- 最小生成树(Kruskal)(并查集)
最小生成树 时间限制: 1 Sec 内存限制: 64 MB提交: 11 解决: 2[提交][状态][讨论版] 题目描述 某个宇宙帝国有N个星球,由于宇宙的空间是三维的,因此每个星球的位置可以用三维 ...
- Linux Shell 量的自增
Linux Shell 中写循环时,常常要用到变量的自增,现在总结一下整型变量自增的方法.我所知道的,bash中,目前有五种方法:1. i=`expr $i + 1`;2. let i+=1;3. ( ...
- [CF986E]Prince's Problem
题意:给一棵带点权$w_i$的树,多次询问$(u,v,x)$,求出$\prod\limits_{i\in\text{path}(u,v)}(w_i,x)$ 因为是乘法,所以可以把路径询问拆成到根询问, ...
- 微服务之SpringCloud实战(三):SpringCloud Eureka高可用
高可用Eureka 高可用我就不再过多解释了,Eureka Server的设计一开始就考虑了高可用的问题,在Eureka的服务治理设计中,所有的节点即是服务提供方也是消费方,注册中心也不例外,上一章中 ...
- 13南理工test01:进制转化
#include<iostream> #include<cstdlib> using namespace std; int main() { //cout<<5/2 ...
- JavaBean的详细及引用
1.JavaBean实际是具有统一接口格式的java类 2.JavaBean的组成:属性(Properties).方法(Method).事件(Events) 3.一个JavaBean的例子(该例子是用 ...