80分,求解

P1086 [NOIP2004 普及组] 花生采摘

#include<bits/stdc++.h> using namespace std; int n,m,t,tmp,ans; struct hs { int x,y; int s; }a[405]; bool cmp(hs x,hs y) { return x.s>y.s; } int main() { cin>>n>>m>>t; int k=0; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { a[++k].x=i; a[k].y=j; cin>>a[k].s; } sort(a+1,a+1+k,cmp); tmp=a[1].x+1; if(tmp*2-1>t) { cout<<"0"; return 0; } ans+=a[1].s; k=1; while(1) { k++; if(a[k].s==0) break; tmp+=abs(a[k].x-a[k-1].x)+abs(a[k].y-a[k-1].y)+1; if(tmp+a[k].x>t) break; if(tmp+a[k].x==t) break; ans+=a[k].s; } cout<<ans; return 0; }
by czk15 @ 2018-02-13 20:03:06


已解决 ~~大佬不要说出我的弱智错误~~
by czk15 @ 2018-02-13 20:09:13


|