OpenJudge / Poj 1928 The Peanuts C++
链接地址:http://bailian.openjudge.cn/practice/1928
题目:
- 总时间限制:
- 1000ms
- 内存限制:
- 65536kB
- 描述
- 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.- 输入
- 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.- 输出
- For each test case, print one line containing the amount of peanuts Dodo can pick.
- 样例输入
- 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
- 样例输出
- 37
- 28
- 来源
- Beijing 2004 Preliminary@POJ
思路:
每次采摘前计算是否能够采摘,模拟题
代码:
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- int m,n,k;
- cin>>m>>n>>k;
- int *arr = new int[m*n];
- for(int i = ; i < m; i++)
- {
- for(int j = ; j < n; j++)
- {
- cin>>arr[i * n + j];
- }
- }
- int sum = ,ni=,nj;
- int max,maxi,maxj;
- k -= ;
- int flag = ;
- do
- {
- max = -;
- for(int i = ; i < m; i++)
- {
- for(int j = ; j < n; j++)
- {
- if(max < arr[i * n + j])
- {
- max = arr[i * n + j];
- maxi = i;
- maxj = j;
- }
- }
- }
- if(flag) {nj = maxj;flag = ;}
- int step = abs(maxi - ni) + abs(maxj - nj) + ;
- if(step + maxi > k) break;
- else
- {
- k -= step;
- sum += max;
- ni = maxi;
- nj = maxj;
- arr[maxi * n + maxj] = ;
- }
- }while();
- cout<<sum<<endl;
- delete [] arr;
- }
- return ;
- }
OpenJudge / Poj 1928 The Peanuts C++的更多相关文章
- OpenJudge / Poj 2141 Message Decowding
1.链接地址: http://poj.org/problem?id=2141 http://bailian.openjudge.cn/practice/2141/ 2.题目: Message Deco ...
- OpenJudge/Poj 2105 IP Address
1.链接地址: http://poj.org/problem?id=2105 http://bailian.openjudge.cn/practice/2105 2.题目: IP Address Ti ...
- OpenJudge/Poj 2027 No Brainer
1.链接地址: http://bailian.openjudge.cn/practice/2027 http://poj.org/problem?id=2027 2.题目: 总Time Limit: ...
- OpenJudge/Poj 2013 Symmetric Order
1.链接地址: http://bailian.openjudge.cn/practice/2013 http://poj.org/problem?id=2013 2.题目: Symmetric Ord ...
- OpenJudge/Poj 1088 滑雪
1.链接地址: bailian.openjudge.cn/practice/1088 http://poj.org/problem?id=1088 2.题目: 总Time Limit: 1000ms ...
- OpenJudge/Poj 2001 Shortest Prefixes
1.链接地址: http://bailian.openjudge.cn/practice/2001 http://poj.org/problem?id=2001 2.题目: Shortest Pref ...
- OpenJudge/Poj 2000 Gold Coins
1.链接地址: http://bailian.openjudge.cn/practice/2000 http://poj.org/problem?id=2000 2.题目: 总Time Limit: ...
- OpenJudge/Poj 1936 All in All
1.链接地址: http://poj.org/problem?id=1936 http://bailian.openjudge.cn/practice/1936 2.题目: All in All Ti ...
- OpenJudge/Poj 1661 帮助 Jimmy
1.链接地址: bailian.openjudge.cn/practice/1661 http://poj.org/problem?id=1661 2.题目: 总Time Limit: 1000ms ...
随机推荐
- IDF实验室-python ByteCode writeup
题目地址:http://ctf.idf.cn/index.php?g=game&m=article&a=index&id=45 下载来发现是crackme.pyc 可以用unc ...
- Xcode7如何添加pch文件
我们在写项目的时候,大部分宏定义,头文件导入都在这里,Xcode6去掉Precompile Prefix Header的主要原因可能在于Prefix Header大大的增加了Build的时间.但是没有 ...
- [React Native] Complete the Notes view
In this final React Native lesson of the series we will finalize the Notes view component and squash ...
- mysql datetime、date、time、timestamp区别
我们看看这几个数据库中(mysql.oracle和sqlserver)如何表示时间 mysql数据库:它们分别是 date.datetime.time.timestamp和year.date :“yy ...
- 深入理解Binder(一),从AIDL谈起
打算写一篇Binder介绍的文章,仔细想想一篇文章貌似很难厘清,于是我打算从AIDL入手,本篇先来简单介绍下AIDL的使用,然后在此基础上我们继续来研究Binder的工作原理.小伙伴们都知道,AIDL ...
- Joseph cicyle's algorithm
约瑟夫环问题: 输入:1)总共人数:2)每次被杀的序号数: 输出:最后一个活着的序号 python代码如下: n=int (input('please input the number of peop ...
- Oracle批量加注释,并生成html
excel连接列名生成oracle注释 notes: A2为列名,B2为注释 ="comment on column ColAgreementHeader."&A2& ...
- SQL的几道题目
1.构造数据插入方案表t_project_finish表 a)将addtime更新为当前时间的前一天 首先想到的是addtime=addtime-1,然后就开始验证这个想法. 插入一行数据,包括主键和 ...
- java编程常用技术
一:将String字符串放在最前面 防止发生NullPointerException异常,我们通常把String字符串放在equals方法的左边来比较,这样可以有效的避免 空指针异常的发生. 第一种情 ...
- nginx配置文件特殊字符说明
开发过程中经常重复配置nginx.conf,对里面的特殊字符始终不太明白具体的意义,今天百度nginx配置看到一篇不错的文章,转载记录下来,以备不时之需. nginx rewrite 正则表达式匹配 ...