POJ-1928-The Peanuts
来源:互联网 发布:分镜头绘制软件 编辑:程序博客网 时间:2024/04/30 12:56
最开始以为是DP,结果贪心就好~囧~
代码:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int maxn=51;struct node{ int x; int y; int val; bool operator <(const node& a)const {return val>a.val; }}a[maxn*maxn];int n,m,k,cur;int main(){ int T; 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); } return 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(水)
- RTX开发教程[第一步:需求]:我想要的rtx网页版后台管理
- 转载:逻辑地址、线性地址、物理地址和虚拟地址
- CRC32编码
- 微端开发 几点经验
- 微端用到的下载代码
- POJ-1928-The Peanuts
- 收集的几种exe嵌入网页的方法(2)
- 收集的几种exe嵌入网页的方法(3)
- 遗留问题汇总
- 收集的几种exe嵌入网页的方法(1)
- 收集的几种exe嵌入网页的方法(4)
- 收集的几种exe嵌入网页的方法(5)
- 收集的几种exe嵌入网页的方法(6)
- 收集的几种exe嵌入网页的方法(7)