and "River" like, in a long time ago I have tried to do this problem, but I did not see the problem. The topic says to find the biggest first, then second. It was a long time, but I didn't do it. But now it's good to do it, just use the structure to record every peanut plant, sort from big to small. Then enumerate the peanuts, each time enumeration to determine the better.
But!! If we change the subject. Instead of looking for the biggest, the maximum number of peanuts found in the specified time period. What should I do? should be the regulation but how to do, think for a long time also did not think out ....
Code:
#include <iostream>#include<cstdio>#include<algorithm>#include<cmath>using namespacestd;structnode{intx,y,c;}; Node h[ -];intN,m,t,sum,tot,px,py,ans;inlineintComp (node A,node b) {returnA.c>B.C;} InlineintDis (node A,node b) {returnABS (a.x-b.x) +abs (a.y-b.y);}intMain () {scanf ("%d%d%d",&n,&m,&t); for(intI=1; i<=n;i++) for(intj=1; j<=m;j++){ intx; scanf ("%d",&x); if(x) h[++tot].x=j,h[tot].y=i,h[tot].c=x; } sort (H+1, h+tot+1, comp); Sum=h[1].y+1; ans=h[1].c; if(sum+h[1].y>t) {printf ("0"); return 0; } for(intI=2; i<=tot;i++) if(Sum+dis (h[i-1],h[i]) +1+H[I].Y>T) Break; ElseSum+=dis (h[i-1],h[i]) +1, ans+=h[i].c; printf ("%d", ans);}
Vijos 1120 Peanut picking