POJ:1928 花生问题 The Peanuts
来源:互联网 发布:淘宝魔镜数据 编辑:程序博客网 时间:2024/04/28 21:34
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
struct pean{
int x,y,num;
}sum[3000];
int cmp(const void *a,const void *b)
{
struct pean *c,*d;
c=(struct pean *)a;
d=(struct pean *)b;
returnd->num-c->num;
}
int main()
{
int q,t,m,n,k,i,j,a,x1,y1,max;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&m,&n,&k);
q=0;
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{
scanf("%d",&a);
if(a>0){
sum[q++].num=a;
sum[q-1].x=i;
sum[q-1].y=j;
}
}
qsort(sum,q,sizeof(sum[0]),cmp);
max=0;
if(k>=2*sum[0].x+1)
{
max=sum[0].num;
x1=sum[0].x;y1=sum[0].y;
k=k-sum[0].x-1;
}
else{
printf("0\n");
continue;
}
for(i=1;i<q;i++)
{
if(k>=abs(x1-sum[i].x)+abs(y1-sum[i].y)+1+sum[i].x)
{
k=k-abs(x1-sum[i].x)-abs(y1-sum[i].y)-1;
x1=sum[i].x;y1=sum[i].y;
max+=sum[i].num;
}
elsebreak;
}
printf("%d\n",max);
}
return 0;
}
#include<stdlib.h>
#include<math.h>
struct pean{
}sum[3000];
int cmp(const void *a,const void *b)
{
}
int main()
{
}
- POJ:1928 花生问题 The Peanuts
- HDU 1355 The Peanuts
- POJ 3185 The Water Bowls
- POJ 1050 To the Max
- POJ 2945 Find the Clones
- poj 2387 Til the Cows Come Home
- poj 1679 The Unique MST(kruskal)
- poj 1426 Find The Multiple
- Poj 2886 Who Gets the Most Candi…
- poj 2996 Help Me with the Game
- poj 2387 : Til the Cows (d…
- poj 2387 Til the Cows Come Home(…
- poj 3083 Children of the Candy C…
- poj 2488
- poj 2241 The Tower of Babylon(DP…
- poj 3275 Ranking the Cows(floyd …
- POJ 1207(The 3n + 1 problem)水题
- hdu 1157 Who's in the Middle(poj…
- NOIP 1199 合并果子终于做出来了…
- ZZULI Greedy Gift Givers Greedy…
- 杭电46道DP牛人总结
- 《奥巴马就本拉登死亡演讲》
- 爆:本拉登早年与苏军作战照…
- POJ:1928 花生问题 The Peanuts
- NOIP 2007 普及组解题报告--…
- 杭电题目分类
- HDU:田忌赛马(1052)
- hdu 1023,catalan,卡特兰数
- HDU:2604 Queuing(发现似乎所有…
- ACM(Association for Computing Ma…
- 如何判断一个数是否为素数
- 世界24大视觉奇图:智商低的…