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 ...
随机推荐
- Nodejs微信与Bot framework通过Direct Line连接
背景 最近开发了一个Bot Framework的小工具,能够通过Luis分析出用户输入的文本,对文本中的StyleNo/FabricNo/TrimNo提取出来,并传入另一个小系统进行查询出结果,包括文 ...
- 【转.解析清晰】你真明白 Python 装饰器么?
原文出处: 武沛齐 装饰器是程序开发中经常会用到的一个功能,用好了装饰器,开发效率如虎添翼,所以这也是Python面试中必问的问题,但对于好多小白来讲,这个功能 有点绕,自学时直接绕过去了, ...
- Codeforces Round 254 (Div. 2)
layout: post title: Codeforces Round 254 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- httpd访问网络配置httpd_can_network_connect
检查网络访问的配置 getsebool -a | grep httpd_can_network_connect 如结果如下 httpd_can_network_connect --> off 则 ...
- 【kmp算法】poj2185 Milking Grid
先对每行求出所有可能的循环节长度(不需要整除). 然后取在所有行中都出现了的,且最小的长度为宽. 然后将每一行看作字符,对所有行求next数组,将n-next[n](对这些行来说最小的循环节长度)作为 ...
- 【二分答案】【最短路】bzoj1614 [Usaco2007 Jan]Telephone Lines架设电话线
对于二分出的答案x而言,验证答案等价于将所有边权>x的边赋成1,否则赋成0,然后判断从1到n的最短路是否<=K. #include<cstdio> #include<cs ...
- python3开发进阶-Django框架的自带认证功能auth模块和User对象的基本操作
阅读目录 auth模块 User对象 认证进阶 一.auth模块 from django.contrib import auth django.contrib.auth中提供了许多方法,这里主要介绍其 ...
- 快速创建Django验证码
# 生成随机验证码图片 import stringfrom random import randint, samplefrom PIL import Image, ImageDraw, ImageFo ...
- Problem T: 零起点学算法15——交换变量
#include<stdio.h> int main() { int a,b,c; scanf("%d %d",&a,&b); c=a; a=b; b= ...
- wait和notify函数的规范代码模板
// The standard idiom for calling the wait method in Java synchronized (sharedObject) { while (condi ...