Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:用了188ms,刚出道没见过世面,想问这题大家都用了多少时间?有好方法能赐教下吗?谢谢!In Reply To:用了188ms,刚出道没见过世面,想问这题大家都用了多少时间?有好方法能赐教下吗?谢谢! Posted by:bhq at 2009-04-27 15:57:44 这个我写的,简单模拟了下 #include<iostream> #include<algorithm> using namespace std; struct node { int x,y; int num; friend bool operator < (const node &a,const node &b) {return a.num>b.num;} }p[2505]; int main() { int t,m,n,k,i,j,num; cin>>t; while(t--) { cin>>m>>n>>k; int l=1; for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { scanf("%d",&num); if(num>0) p[l].x=i,p[l].y=j,p[l++].num=num; } } sort(p+1,p+l); p[0].x=0,p[0].y=p[1].y,p[0].num=0; int re=0,time=0,a,b; for(i=1;i<l;i++) { a=abs(p[i].x-p[i-1].x)+abs(p[i].y-p[i-1].y)+1; b=p[i].x; if(time+a+b<=k) { re+=p[i].num; time+=a; } else break; } cout<<re<<endl; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator