洛谷 P2958 [USACO09OCT]木瓜的丛林Papaya Jungle
题目描述
Bessie has wandered off the farm into the adjoining farmer's land. He raises delicious papaya fruit, which is a delicacy for cows. The papaya jungle is partitioned into a grid of squares with R rows and C columns (1 <= R <= 40, 1 <= C <= 40), as is popular in Wisconsin. Bessie can travel from a given square to any existing adjacent square whose route is parallel to the X or Y axis. So in the
following diagram, if Bessie is at the square labeled 'B', she can travel to any of the squares labeled 'T':
.T. TBT .T. Bessie always starts out by munching the papayas in square
(row=1,col=1). After she's done with one square, Bessie always uses her trusty binoculars to count the low-hanging fruit in each of the adjacent squares. She then always moves to the square with the most visible uneaten fruit (a square that happily is always unique).
Sooner or later, following this rule, Bessie always ends up in square (R,C) and eats the fruit there.
Given the dimensions of the papaya jungle and the amount of fruit F_ij in each square (1 <= F_ij <= 100), determine the total number of fruit Bessie consumes for a given papaya jungle.
POINTS: 80
Bessie不小心游荡出Farmer John的田地,而走进了相邻的农民的地里。她举起一个木瓜,木瓜对奶牛来说可是不可多得得美味。这个木瓜林像一般的威斯康星州的田地一样被分割成一个R行C列的网格(1 <= R <= 40, 1 <= C <= 40)。Bessie可以从一个格沿着一条跟X轴或Y轴平行的直线走到邻接的另一个格。Bessie发现一开始她自己在木瓜林的(1,1),也就是第一行第一列慢悠悠地咀嚼着木瓜。
Bessie总是用她最信赖地双筒望远镜去数每一个邻接的格里挂着的木瓜的数目。然后她就游荡到那个有最多没有被吃掉的木瓜的邻接的格子(保证这样的格子只有一个)。
按照这种移动方法,最终Bessie总是会在(R,C)停止然后吃掉那里的木瓜。
给定这个木瓜林的大小及每个格的木瓜数F_ij(1 <= F_ij <= 100), 要求Bessie一共吃了多少个木瓜。
输入输出格式
输入格式:
Line 1: Two space-separated integers: R and C
- Lines 2..R+1: Line i+1 describes row i of the jungle with C
space-separated integers that tell how many fruit are in each square: F_i1, F_i2, ..., F_iC
输出格式:
- Line 1: A single integer that is the total number of papayas that Bessie eats by the time she finishes off the papayas at the barn in the lower right corner at coordinate (R,C).
输入输出样例
说明
Three rows; four columns. Bessie starts in upper left corner at the '3'.
Bessie eats the papayas in the order given by the letters next to the numbers below:
(1,1) ---> (1,C)
(1,1) 3a 3 4g 5h (1,C)
| 4b 5c 3f 2i |
(R,1) 1 7d 4e 2j (R,C)
(R,1) ---> (R,C)
She declines to eat 4 of the papayas but consumes 39 (visiting all but two squares of the grid).
思路:模拟。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,ans;
int map[][],vis[][];
void dfs(int x,int y){
ans+=map[x][y];
map[x][y]=;
if(x==n&&y==m){
cout<<ans;
exit();
}
int dx=map[x-][y];
int dy=map[x+][y];
int dz=map[x][y+];
int dc=map[x][y-];
if(dx>dy&&dx>dz&&dx>dc) dfs(x-,y);
if(dy>dx&&dy>dz&&dy>dc) dfs(x+,y);
if(dz>dy&&dz>dx&&dz>dc) dfs(x,y+);
if(dc>dy&&dc>dz&&dc>dx) dfs(x,y-);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
scanf("%d",&map[i][j]);
dfs(,);
return ;
}
洛谷 P2958 [USACO09OCT]木瓜的丛林Papaya Jungle的更多相关文章
- 洛谷——P2958 [USACO09OCT]木瓜的丛林Papaya Jungle
P2958 [USACO09OCT]木瓜的丛林Papaya Jungle 题目描述 Bessie has wandered off the farm into the adjoining farmer ...
- 洛谷 P2376 [USACO09OCT]津贴Allowance 解题报告
P2376 [USACO09OCT]津贴Allowance 题目描述 作为创造产奶纪录的回报,\(Farmer\) \(John\)决定开始每个星期给\(Bessie\)一点零花钱. \(FJ\)有一 ...
- 洛谷—— P1339 [USACO09OCT]热浪Heat Wave
P1339 [USACO09OCT]热浪Heat Wave 题目描述 The good folks in Texas are having a heatwave this summer. Their ...
- 洛谷 P2959 [USACO09OCT]悠闲漫步The Leisurely Stroll
P2959 [USACO09OCT]悠闲漫步The Leisurely Stroll 题目描述 Bessie looks out the barn door at the beautiful spri ...
- 洛谷 P2960 [USACO09OCT]Milkweed的入侵Invasion of the Milkweed
P2960 [USACO09OCT]Milkweed的入侵Invasion of the Milkweed 题目描述 Farmer John has always done his best to k ...
- 洛谷P1339 [USACO09OCT]热浪Heat Wave 题解
题目传送门 这道题实际非常简单好奇是怎么变黄的... 其实也就是一个SPFA,本人非常懒,不想打邻接表,直接用矩阵就好啦... #include<bits/stdc++.h> using ...
- 洛谷 P2639 [USACO09OCT]Bessie的体重问题Bessie's We… 题解
题目传送门 这也是个01背包,只是装的很... #include<bits/stdc++.h> #define MAXN 45010 using namespace std; int f[ ...
- 洛谷 2957 [USACO09OCT]谷仓里的回声Barn Echoes
题目描述 The cows enjoy mooing at the barn because their moos echo back, although sometimes not complete ...
- 洛谷——2639[USACO09OCT]Bessie的体重问题Bessie's We…——01
题目描述 Bessie像她的诸多姊妹一样,因为从Farmer John的草地吃了太多美味的草而长出了太多的赘肉.所以FJ将她置于一个及其严格的节食计划之中.她每天不能吃多过H (5 <= H & ...
随机推荐
- 洛谷3962 [TJOI2013]数字根
题目描述 一个数字的数字根定义为:这个数字每一位的数字加起来求和,反复这个过程直到和小于10.例如,64357的数字跟为7,因为6+4+3+5+7=25,2+5=7个区间的数字根定义为这个区间所有数字 ...
- 二、 HBase核心功能模块。
Hadoop 框架包含两个核心组件: HDFS 和 MapReduce 其中 HDFS 是文件存储系统,负责数据存储: MapReduce 是 ...
- ArcGIS api for javascript——设置自定义范围和空间参考
描述 这个示例展示了在创建地图时如果定义一个自定义的范围和空间参考. 在 ArcGIS JavaScript API的1.0和1.1版本,任何要使用的地图服务图层都需要和地图的空间参考一致.1.2版本 ...
- 移动App架构设计
移动App架构设计 本文主要总结了几种经常使用的架构模式, 基本是层层递进的转载请注名出处 http://blog.csdn.net/uxyheaven, 良好的排版在https://github.c ...
- javascript对象如何使用
javascript对象如何使用 一.总结 一句话总结:JavaScript 中的所有事物都是对象:字符串.数值.数组.函数... 因为函数是对象,所以自定义对象的创建中有种方法就是函数 1.js中的 ...
- sqlserver bulk insert
开启功能 -- To allow advanced options to be changed. EXEC sp_configure 'show advanced options', 1 GO -- ...
- IBM软件技术峰会归来
为期两天在北京国际饭店会议中心的IBM软件技术峰会已近结束,此次大会最大的收获是能和沃森实验室的王博士沟通探讨人工智能软件的发展问题.领略到IBM 云计算首席架构师Jason R.McGee如何呼风唤 ...
- ajax跨域过程
- element-ui表格控件前端分页方法
<div id="app"> <el-table :data="tableData.slice((currentPage-1)*pageSize,cur ...
- BZOJ3105: [cqoi2013]新Nim游戏(Xor线性无关组)
Description 传统的Nim游戏是这样的:有一些火柴堆,每堆都有若干根火柴(不同堆的火柴数量可以不同).两个游戏者轮流操作,每次可以选一个火柴堆拿走若干根火柴.可以只拿一根,也可以拿走整堆火柴 ...