POJ1928 The Peanuts
来源:互联网 发布:android 仿淘宝详情 编辑:程序博客网 时间:2024/04/30 13:22
原题
Description
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
26 7 210 0 0 0 0 0 00 0 0 0 13 0 00 0 0 0 0 0 70 15 0 0 0 0 00 0 0 9 0 0 00 0 0 0 0 0 06 7 200 0 0 0 0 0 00 0 0 0 13 0 00 0 0 0 0 0 70 15 0 0 0 0 00 0 0 9 0 0 00 0 0 0 0 0 0Sample Output
3728
昨天看了半天也没弄明白O__O “…
还是英语问题啊 T^T
详细的解释在这里
我写的代码如下:
#include <iostream> #include <cstdio> #include <math.h>using namespace std;int main(){ #ifndef ONLINE_JUDGE freopen("1.txt", "r", stdin); #endif int t, m , n, k, sum; int a[55][55]; int i, j; int cur_i, cur_j, next_i, next_j, max_num, time; cin >> t; while(t--) { scanf("%d%d%d", &m, &n, &k); for (i = 1; i <= m; i++) { for (j = 1; j <= n; j++) { scanf("%d", &a[i][j]); } } cur_i = 0; sum = 0; time = 0; next_i = 1; next_j = 1; while(k >= time) { max_num = 0; for (i = 1; i <= m; i++) { for (j = 1; j <= n; j++) { if (max_num < a[i][j]) { next_i = i; next_j = j; max_num = a[i][j]; } } } //cout << a[next_i][next_j] << endl; if (!max_num) { break; } if (!cur_i) { cur_j = next_j; } if(k >= time + abs(next_i - cur_i) + abs(next_j - cur_j) + 1 +next_i) { sum += a[next_i][next_j]; a[next_i][next_j] = 0; time += abs(next_i - cur_i) + abs(next_j - cur_j) + 1; cur_j = next_j; cur_i = next_i; } else { break; } } cout << sum << endl; } return 0;}
0 0
- POJ1928 The Peanuts
- POJ1928 The Peanuts
- ZOJ2235 POJ1928 HDU1355 The Peanuts
- POJ1928
- poj1928
- fjnu 1013 The Peanuts
- pku 1928 The Peanuts
- poj 1928 The Peanuts
- hdu 1355 The Peanuts
- hdu1355 The Peanuts
- POJ-1928-The Peanuts
- POJ 1928 The Peanuts
- POJ 1928 The Peanuts
- POJ 1928 The Peanuts
- hdu 1355 The Peanuts(DP)
- HDOJ 1355 The Peanuts(水)
- POJ 1928 The Peanuts 笔记
- The Peanuts--很水的模拟题~~
- Android-菜单库-ArcMenu、LineMenu、RoundMenu
- 树的层序遍历(深度优先 和 队列)
- Poj 1611 The Suspects
- 实习小结——UIBarButtonItem和UINavigationBar的坑
- 运营开发规范化
- POJ1928 The Peanuts
- swappiness调整的调整
- HTML学习笔记(4)——CSS块级元素与盒模型
- Lucene全文检索
- Base64的简单使用
- HDFS的认识和理解
- linux下的文件权限
- 机房重构(二)--MDI窗体问题+优化的单例模式
- Keil MDK 点击增量编译 一直全部重新编译的解决办法