Vijos 1120 Peanut picking

Source: Internet
Author: User

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&GT;T) Break; ElseSum+=dis (h[i-1],h[i]) +1, ans+=h[i].c; printf ("%d", ans);}

Vijos 1120 Peanut picking

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.