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(推理)的更多相关文章

  1. HDU 4925 Apple Tree (瞎搞)

    找到规律,各一个种一棵树.或者施肥.先施肥,先种树一样. Apple Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 2621 ...

  2. HDU 4925 Apple Tree(模拟题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 解题报告:给你n*m的土地,现在对每一块土地有两种操作,最多只能在每块土地上进行两种操作,第一种 ...

  3. 2014多校第六场 1005 || HDU 4925 Apple Tree

    题目链接 题意 : 给你一块n×m的矩阵,每一个格子可以施肥或者是种苹果,种一颗苹果可以得到一个苹果,但是如果你在一个格子上施了肥,那么所有与该格子相邻(指上下左右)的有苹果树的地方最后得到的苹果是两 ...

  4. 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 ...

  5. hdoj 4925 Apple tree 【最小割】

    题目:pid=4925">hdoj 4925 Apple tree 来源:2014 Multi-University Training Contest 6 题意:给出一个矩阵,然后每一 ...

  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 ...

  7. HDU-4925 Apple Tree

    http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others)     ...

  8. HDU 6206 Apple (高精确度+JAVA BigDecimal)

    Problem Description Apple is Taotao's favourite fruit. In his backyard, there are three apple trees ...

  9. POJ 2486 Apple Tree

    好抽象的树形DP......... Apple Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6411 Accepte ...

随机推荐

  1. C# T4使用

    最近升级我们的框架到微服务了,而且是dotnetcore 2.0. 然后一个新的框架,最基本的Model和与数据库交互的Repository,我们都是要利用T4自动生成的. 首先这个是代码结构,在这个 ...

  2. windows8 使用docker创建第一个nodejs运行环境

    现在公司电脑使用的是windows8操作系统,如果想要运行docker,只能安装Docker ToolBox 关于安装Docker ToolBox,请查看文章<windows8安装docker( ...

  3. [thinkphp] ajaxReturn案例

    javascript: <script> $('.ajax-post').click(function(){ var action_url=$('form').attr('action') ...

  4. [thinkphp] U方法域名支持

    域名支持如果你的应用涉及到多个子域名的操作地址,那么也可以在U方法里面指定需要生成地址的域名,例如: U('Blog/read@blog.thinkphp.cn','id=1'); @后面传入需要指定 ...

  5. python3 while循环及for循环

    yueer = 18 count = 0 while count < 3: yueerage = int(input('悦儿多大呢:')) if yueerage == yueer: print ...

  6. [Hackerrank]时间转换Time Conversion

    题目链接 大致要求是说给定一个十二小时制的时间,给出它的二十四小时制的形式. 输入格式:hh:mm:ssAM 或者 hh:mm:ssPM,其中01≤hh≤12,00≤mm,ss≤59 思路 判断字符串 ...

  7. 某道我xjb想的题

    Function 时限:5s 空限:256M (都是单点) Discription 现在你有一个函数: inline int f(int x){ int tot=0,alr=0,now; while( ...

  8. 【贪心】Codeforces Round #401 (Div. 2) D. Cloud of Hashtags

    从后向前枚举字符串,然后从左向右枚举位. 如果该串的某位比之前的串的该位小,那么将之前的那串截断. 如果该串的某位比之前的串的该位大,那么之前那串可以直接保留全长度. 具体看代码. #include& ...

  9. 1.5 JSP标准标签库(JSTL)(核心标签 out、set、remove、if、choose、forEach、forTokens、redirect)

    JSTL(JavaServer Page Standard Tag  Library):JSP标准标签库.它封装了JSP应用的通用核心功能. 1.准备工作 使用JSTL前需要下载所需文件,下载地址及安 ...

  10. duplicate symbol _gestureMinimumTranslation in:

    在真机上编译无误,在模拟器上编译报错:duplicate symbol _gestureMinimumTranslation in: /Users/Sam/Library/Developer/Xcod ...