hdu1355 The Peanuts
来源:互联网 发布:c标签和js函数 编辑:程序博客网 时间:2024/04/30 15:56
单纯的贪心就可以
#include <cstdio>#include <algorithm>#include <cmath>using namespace std;struct PEA { int row, column, data;}pea[2505];bool cmp ( PEA a, PEA b ) { return a.data > b.data;}int ct, num, m, n, k, x;int main ( ) { while ( scanf ( "%d", &ct ) != EOF ) { while ( ct-- ) { num = 0; scanf ( "%d%d%d", &m, &n, &k ); for ( int i = 0; i < m; ++i ) for ( int j = 0; j < n; ++j ) { scanf ( "%d", &x ); if ( x > 0 ) { pea[num].row = j; pea[num].column = i; pea[num++].data = x; } } sort ( pea, pea + num , cmp ); if ( 2 * pea[0].column + 3 > k ) { printf ( "0\n" ); continue; } double tmp = pea[0].column + 3.0; int ans = pea[0].data; for ( int i = 1; i < num; ++i ) { double tm = abs ( pea[i].row - pea[i - 1].row ) + fabs ( pea[i].column - pea[i - 1].column ); if ( tm + tmp + pea[i].column + 1.0 > k ) break; tmp += tm + 1.0; ans += pea[i].data; } printf ( "%d\n", ans ); } }}
- hdu1355 The Peanuts
- ZOJ2235 POJ1928 HDU1355 The Peanuts
- fjnu 1013 The Peanuts
- pku 1928 The Peanuts
- poj 1928 The Peanuts
- hdu 1355 The Peanuts
- POJ-1928-The Peanuts
- POJ1928 The Peanuts
- POJ1928 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--很水的模拟题~~
- 杭电OJ 1355:The Peanuts
- ACM篇:POJ 1928--The Peanuts
- fortran大型数组的二进制存储-matlab读取
- hibernate3中出现 could not initialize proxy - no Session 错误的解决办法以及lazy load的介绍
- EasyUI Tree+Asp.net实现权限树或目录树导航
- 关于platform_device和platform_driver的匹配
- 联合查询与多表查询基础详解
- hdu1355 The Peanuts
- 资源内存管理
- hibernate前2天的简单总结
- struts2 iterator标签使用
- 基于垃圾回收的资源管理
- 动态加载资源
- IOS之同步请求、异步请求、GET请求、POST请求
- nexus 安装与配置(一)
- 14.输入一个已经按升序排序过的数组和一个数字, 在数组中查找两个数,使得它们的和正好是输入的那个数字。