链接地址: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.
样例输入
  1. 2
  2. 6 7 21
  3. 0 0 0 0 0 0 0
  4. 0 0 0 0 13 0 0
  5. 0 0 0 0 0 0 7
  6. 0 15 0 0 0 0 0
  7. 0 0 0 9 0 0 0
  8. 0 0 0 0 0 0 0
  9. 6 7 20
  10. 0 0 0 0 0 0 0
  11. 0 0 0 0 13 0 0
  12. 0 0 0 0 0 0 7
  13. 0 15 0 0 0 0 0
  14. 0 0 0 9 0 0 0
  15. 0 0 0 0 0 0 0
样例输出
  1. 37
  2. 28
来源
Beijing 2004 Preliminary@POJ

思路:

每次采摘前计算是否能够采摘,模拟题

代码:

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int t;
  8. cin>>t;
  9. while(t--)
  10. {
  11. int m,n,k;
  12. cin>>m>>n>>k;
  13. int *arr = new int[m*n];
  14. for(int i = ; i < m; i++)
  15. {
  16. for(int j = ; j < n; j++)
  17. {
  18. cin>>arr[i * n + j];
  19. }
  20. }
  21. int sum = ,ni=,nj;
  22. int max,maxi,maxj;
  23. k -= ;
  24. int flag = ;
  25. do
  26. {
  27. max = -;
  28. for(int i = ; i < m; i++)
  29. {
  30. for(int j = ; j < n; j++)
  31. {
  32. if(max < arr[i * n + j])
  33. {
  34. max = arr[i * n + j];
  35. maxi = i;
  36. maxj = j;
  37. }
  38. }
  39. }
  40. if(flag) {nj = maxj;flag = ;}
  41. int step = abs(maxi - ni) + abs(maxj - nj) + ;
  42. if(step + maxi > k) break;
  43. else
  44. {
  45. k -= step;
  46. sum += max;
  47. ni = maxi;
  48. nj = maxj;
  49. arr[maxi * n + maxj] = ;
  50. }
  51.  
  52. }while();
  53. cout<<sum<<endl;
  54. delete [] arr;
  55. }
  56. return ;
  57. }

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. 使用教程sqlite

    访问地址: http://www.runoob.com/sqlite/sqlite-where-clause.html

  2. git 几款好用的客户端工具

    虽然git命令非常好用,但客户端UI工具掌握起来.使用起来更加容易.如果你不想用git命令的话,那就用UI工具代替吧. 下面介绍下几款好用的git工具 1.tortoiseGit for Mac (这 ...

  3. POJ 2003 Hire and Fire (Tree)

    题目:Hire and Fire 题目翻译成数据结构就是:建树,加结点,删除结点,打印结点.只有删除结点稍微复杂点,因为删除设计掉树的调整. 首先要考虑树怎么存储才能使解题更顺手. 1.我们要存储每个 ...

  4. 【转】来自《轻松scrum之旅》的敏捷开发总结

    敏捷开发的核心价值观是,软件开发最重要的是给用户提供有价值的.可以工作的软件.如何保证提供有价值的软件,是通过反馈机制来完成的.这一点,我们体会很深.自从采用敏捷开发以后,我们比以前更有意识地希望得到 ...

  5. 解决Please ensure that adb is correctly located at 'D:\java\sdk\platform-tools\adb.exe' and can be executed.

    遇到问题描述: 运行android程序控制台输出 [2012-07-18 16:18:26 - ] The connection to adb is down, and a severe error ...

  6. android的ListView做表格添加圆角边框

    边框,圆角,都可以实现的 在drawable目录下添加view_yuan_morelist.xml,设置控件的边框代码.如下: <?xml version="1.0" enc ...

  7. 《Java并发编程实战》第十一章 性能与可伸缩性 读书笔记

    造成开销的操作包含: 1. 线程之间的协调(比如:锁.触发信号以及内存同步等) 2. 添加�的上下文切换 3. 线程的创建和销毁 4. 线程的调度 一.对性能的思考 1 性能与可伸缩性 执行速度涉及下 ...

  8. Android手机中获取手机号码和运营商信息

    代码如下: package com.pei.activity; import android.app.Activity; import android.os.Bundle; import androi ...

  9. windows MySQL 5+ 服务手动安装

    一.手动安装mysql 1.准备一个mysql免安装版本(把原来安装好的版本复制一份即可.一次安装多次使用^_^),将mysql复制到指定目录. 2.配置my.ini文件(本例使用的是5.0.22版本 ...

  10. GPS(Global Positioning System)全球定位系统

    GPS构成: 1.空间部分 GPS的空间部分是由24 颗工作卫星组成,它位于距地表20 200km的上空,均匀分布在6 个轨道面上(每个轨道面4 颗) ,轨道倾角为55°.此外,还有4 颗有源备份卫星 ...