The Peanuts--很水的模拟题~~

2024-03-01 23:32
文章标签 模拟题 很水 peanuts

本文主要是介绍The Peanuts--很水的模拟题~~,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目描述:

  Mr. Robinson and his pet monkey Dodo love peanuts very much. One day while they were having a walk on a country road, Dodo found a sign by the road, pasted with a small piece of paper, saying "Free Peanuts Here! " You can imagine how happy Mr. Robinson and Dodo were.

There was a peanut field on one side of the road. The peanuts were planted on the intersecting points of a grid as shown in Figure-1. At each point, there are either zero or more peanuts. For example, in Figure-2, only four points have more than zero peanuts, and the numbers are 15, 13, 9 and 7 respectively. One could only walk from an intersection point to one of the four adjacent points, taking one unit of time. It also takes one unit of time to do one of the following: to walk from the road to the field, to walk from the field to the road, or pick peanuts on a point.

According to Mr. Robinson's requirement, Dodo should go to the plant with the most peanuts first. After picking them, he should then go to the next plant with the most peanuts, and so on. Mr. Robinson was not so patient as to wait for Dodo to pick all the peanuts and he asked Dodo to return to the road in a certain period of time. For example, Dodo could pick 37 peanuts within 21 units of time in the situation given in Figure-2.

Your task is, given the distribution of the peanuts and a certain period of time, tell how many peanuts Dodo could pick. You can assume that each point contains a different amount of peanuts, except 0, which may appear more than once.

Input

The first line of input contains the test case number T (1 <= T <= 20). For each test case, the first line contains three integers, M, N and K (1 <= M, N <= 50, 0 <= K <= 20000). Each of the following M lines contain N integers. None of the integers will exceed 3000. (M * N) describes the peanut field. The j-th integer X in the i-th line means there are X peanuts on the point (i, j). K means Dodo must return to the road in K units of time.

Output

For each test case, print one line containing the amount of peanuts Dodo can pick

Sample Input

2
6 7 21
0 0 0 0 0 0 0
0 0 0 0 13 0 0
0 0 0 0 0 0 7
0 15 0 0 0 0 0
0 0 0 9 0 0 0
0 0 0 0 0 0 0
6 7 20
0 0 0 0 0 0 0
0 0 0 0 13 0 0
0 0 0 0 0 0 7
0 15 0 0 0 0 0
0 0 0 9 0 0 0
0 0 0 0 0 0 0

 

Sample Output

37
28
这题绝对是一道水题,纯粹用来考英文的,题目大致意思是给你一个m*n矩
阵,在一定时间k内能摘的花生最多,而每次都是去含最多花生的节点上摘,
所以只要对每个节点上的花生数排序,同时记录他的xy坐标,取的时候从上
往下,看够不够时间这个节点上的花生,够的话摘,不够退出。但这里有
个注意点,就是关于结构体的排序
 struct ss
  • {
  •   int p,x,y;
  •   bool operator<(const ss b ) const
  •   {
  •     return (p<b.p);
  •   }
  • };
 需要重载<符号,这样就可以像int一样比较两个结构体的大小了,排序
就可以调用sort,qsort了,我这里用的是set,其实就排序效率来讲都
差不多的;
代码:
           

这篇关于The Peanuts--很水的模拟题~~的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/764189

相关文章

机试算法模拟题 服务中心选址

题目描述 一个快递公司希望在一条街道建立新的服务中心。公司统计了该街道中所有区域在地图上的位置,并希望能够以此为依据为新的服务中心选址:使服务中心到所有区域的距离的总和最小。 给你一个数组positions,其中positions[i] = [left, right] 表示第 i 个区域在街道上的位置,其中left代表区域的左侧的起点,right代表区域的右侧终点,假设服务中心的位置为loca

HDU 1332(模拟题,电子数字)

#include <iostream>#include <cstring>using namespace std;#define MAXLENGTH 8void lcd_display (long size, long number){// 将number拆分为单个的数字。int digits[MAXLENGTH];memset (digits, -1, sizeof (

AcWing 1801:蹄子剪刀布 ← 模拟题

【题目来源】https://www.acwing.com/problem/content/1803/【题目描述】 你可能听说过“石头剪刀布”的游戏。 这个游戏在牛当中同样流行,它们称之为“蹄子剪刀布”。 游戏的规则非常简单,两头牛相互对抗,数到三之后各出一个表示蹄子,剪刀或布的手势。蹄子赢剪刀,剪刀赢布,布赢蹄子。 例如,第一头牛出“蹄子”手势,第二头牛出“布”手势,则第二头牛获胜。 如果两头牛出

Elasticsearch 认证模拟题 - 22

一、题目 索引 task 索引中文档的 fielda 字段内容包括了 hello & world,索引后,要求使用 match_phrase query 查询 hello & world 或者 hello and world 都能匹配该文档 1.1 考点 分词器 1.2 答案 # 创建符合条件的 task 索引,设置 field 字段,并写入数据PUT task{"settings

模拟题1(考虑周全以及情况较多)

牛客小白月赛96(重现赛)D题 题目解析以及注意事项 该题主要是找线路最多和最少的各种情况,从而达到整体连通图的构建代价最小的情况。 注意事项:a,b的正负影响着这个图的线尽可能的多还是少 思路图 { a ≥ b { b < 0 a < 0 : 能连的线都连上 b < 0 a ≥ 0 :奇偶性不同线能连的的全连上 b > 0 :连奇偶性不同的点,而且线的数量要尽量小 a < b { a <

Elasticsearch 认证模拟题 - 21

一、题目 写一个查询,要求查询 kibana_sample_data_ecommerce 索引,且 day_of_week、customer_gender、currency、type 这 4 个字段中至少两个以上。 1.1 考点 Boolean 1.2 答案 GET kibana_sample_data_ecommerce/_search{"query": {"bool": {"sho

hodj 1008 Elevator (模拟题)

个人写的代码不够简洁,而且在处理这种多循环的代码时,每次循环时变量没有重新赋值为0,造成了调试了好几次代码才通过,这是不应该的。在这次代码中,time和current都没有重新赋值为0,下回应该注意。还要网友在代码中对题目的中时间常量进行了赋值,这一点很好,要学习。 代码如下: #include <iostream>#include <algorithm>#include <string>

Elasticsearch 认证模拟题 - 17

这两道题目非常具有代表性,分别是跨集群复制和跨集群检索,需要相应的 许可 这里在虚拟机上搭建集群完成这两道题目,这里补充一下 elasticsearch 和 kibana 的配置文件 # elasticsearch.ymlcluster.name: cluster2node.name: cluster2-nodepath.data: /home/jie/es8/cluster2/data

Elasticsearch 认证模拟题 - 14

一、题目 在集群中输入以下指令: PUT phones/_doc/1{"brand":"Samsumg","model":"Galaxy S9+","features":[{"type":"os", "value":"Android"},{"type":"storage", "value":"64"},{"type":"camera_resolution", "value":"12"}]}

Elasticsearch 认证模拟题 - 16

一、题目 创建一个搜索模版,要求 match_prase 查询,并且用指定的格式高亮,并排序 # 创建索引PUT my_index{"settings": {"number_of_replicas": 0,"number_of_shards": 1},"mappings": {"properties": {"a":{"type": "text"},"b":{"type": "integer