POJ 1928 The Peanuts
来源:互联网 发布:telnet不通公网80端口 编辑:程序博客网 时间:2024/04/30 09:28
贪心法即可。先将花生最多的格点排序,然后以此判断能否到达并返回。
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>using namespace std;const int MAXN = 55;struct Node{int x, y, val;bool operator <(const Node& a) const{return val > a.val;}}a[MAXN * MAXN];int main(){int t, n, m, k, cur;scanf("%d", &t);while (t--){scanf("%d%d%d", &n, &m, &k);cur = 0;for (int i = 0; i < n; i++)for (int j = 0; j < m; j++){int ita;scanf("%d", &ita);if (ita){a[cur].x = i + 1;a[cur].y = j + 1;a[cur++].val = ita;}}sort(a, a + cur);int ans = 0, cou = 0;if (k < a[0].x * 2 + 1){printf("0\n");continue;}ans += a[cou].val;k -= a[cou++].x + 1;while (k > 0 && cou < cur){if(k < abs(a[cou].x-a[cou-1].x) + abs(a[cou].y-a[cou-1].y) + 1 + a[cou].x)break;ans += a[cou].val;k -= abs(a[cou].x - a[cou - 1].x) + abs(a[cou].y - a[cou - 1].y) + 1;cou++;}printf("%d\n", ans);}}
0 0
- poj 1928 The Peanuts
- POJ-1928-The Peanuts
- POJ 1928 The Peanuts
- POJ 1928 The Peanuts
- POJ 1928 The Peanuts
- POJ 1928 The Peanuts 笔记
- ACM篇:POJ 1928--The Peanuts
- poj 1928 peanuts 排序
- pku 1928 The Peanuts
- POJ:1928 花生问题 The Peanuts
- fjnu 1013 The Peanuts
- hdu 1355 The Peanuts
- hdu1355 The Peanuts
- POJ1928 The Peanuts
- POJ1928 The Peanuts
- ZOJ2235 POJ1928 HDU1355 The Peanuts
- hdu 1355 The Peanuts(DP)
- HDOJ 1355 The Peanuts(水)
- 字符串批量替换工具,R资源id动态获取
- php 读取文件自身内容,与读取文件输出内容
- activity的生命周期
- test
- 数据库有数据,但查询不到数据,没查到还爆空指针
- POJ 1928 The Peanuts
- .NET框架
- Linux 中断之下半部机制
- Ubuntu find 命令
- Java内功提升之封装
- poj 1236 Network of Schools(强连通分量 Tarjan算法)
- IOS控件学习:UILabel常用属性与用法
- iOS_ARC下需要release 的情况
- Android:在子线程中更新UI,解析异步消息处理机制(Handler)