链接地址: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++的更多相关文章

  1. OpenJudge / Poj 2141 Message Decowding

    1.链接地址: http://poj.org/problem?id=2141 http://bailian.openjudge.cn/practice/2141/ 2.题目: Message Deco ...

  2. OpenJudge/Poj 2105 IP Address

    1.链接地址: http://poj.org/problem?id=2105 http://bailian.openjudge.cn/practice/2105 2.题目: IP Address Ti ...

  3. OpenJudge/Poj 2027 No Brainer

    1.链接地址: http://bailian.openjudge.cn/practice/2027 http://poj.org/problem?id=2027 2.题目: 总Time Limit: ...

  4. OpenJudge/Poj 2013 Symmetric Order

    1.链接地址: http://bailian.openjudge.cn/practice/2013 http://poj.org/problem?id=2013 2.题目: Symmetric Ord ...

  5. OpenJudge/Poj 1088 滑雪

    1.链接地址: bailian.openjudge.cn/practice/1088 http://poj.org/problem?id=1088 2.题目: 总Time Limit: 1000ms ...

  6. OpenJudge/Poj 2001 Shortest Prefixes

    1.链接地址: http://bailian.openjudge.cn/practice/2001 http://poj.org/problem?id=2001 2.题目: Shortest Pref ...

  7. OpenJudge/Poj 2000 Gold Coins

    1.链接地址: http://bailian.openjudge.cn/practice/2000 http://poj.org/problem?id=2000 2.题目: 总Time Limit: ...

  8. OpenJudge/Poj 1936 All in All

    1.链接地址: http://poj.org/problem?id=1936 http://bailian.openjudge.cn/practice/1936 2.题目: All in All Ti ...

  9. OpenJudge/Poj 1661 帮助 Jimmy

    1.链接地址: bailian.openjudge.cn/practice/1661 http://poj.org/problem?id=1661 2.题目: 总Time Limit: 1000ms ...

随机推荐

  1. 2016 Mac OS 10.11 CocoaPods的安装问题

    CocoaPods的安装问题: 1.首先用淘宝的Ruby镜像来访问CocoaPods,打开终端输入以下命令: (1)gem sources --remove  https://rubygems.org ...

  2. mybatis 打印sql log配置

    mybatis 打印sql log, 方便调试.如何配置呢? log4j.xml : <!-- 打印sql start --> <appender name="IBatis ...

  3. SAP ABAP 处理字符串串串串串串串串(详细)

    关于ABAP中处理字符串的方法,非常详细,学习过程中总结一下分享给大家,,, ABAP/4 提供多个处理类型 C 即字符串 的数据对象的关键字. 处理字符串 的方法有: 1.拆分字符串split 2. ...

  4. C++中str1::function和bind

    在C++的TR1中(TechnologyReport)中包括一个function模板类和bind模板函数,使用它们能够实现类似函数指针的功能,但却却比函数指针更加灵活,特别是函数指向类的非静态成员函数 ...

  5. uva 11246 - K-Multiple Free set(数论)

    题目链接:uva 11246 - K-Multiple Free set 题目大意:给定n,k.求一个元素不大于n的子集,要求该子集的元素尽量多,而且不含两个数满足a∗k=b. 解题思路:容斥原理.f ...

  6. WdatePicker开始日期不能大于结束日期

    <input class="input_calendar inputcss" id="startDate" runat="server" ...

  7. 网络防火墙实战-基于pfsense(1)

    pfSense是一个免费的,开源的FreeBSD作为防火墙和路由器专为使用自定义版本.除了 是一个功能强大的,灵活的防火墙和路由平台,它包括一个长长的清单相关的功能,并允许进一步的扩展包,不添加膨胀和 ...

  8. iOS开发——面试笔试精华(二)

    面试笔试精华(二) 警告:一定要把英文题目过一遍,有些公司的题目故意弄成英文的!!! 1.        Difference between shallow copy and deep copy? ...

  9. sphinx配置文件继承

    # # Minimal Sphinx configuration sample (clean, simple, functional) # source mysql { type = mysql #数 ...

  10. C 高级编程4 makefile 与 IO

    make 与 makefile .目标的语法 目标名:依赖目标 @命令 @命令 make的命令行使用 make -f make 脚本文件 目标名 .目标的划分 demo.mk demo: gcc -c ...