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 |
一次ac。附上代码。参考。大牛直接忽视即可#include<iostream> #include<math.h> using namespace std; int a[100][100]; int main() { int t,m,n,k,i,j,sum; cin>>t; while(t--) { sum=0; cin>>m>>n>>k; for(i=1;i<=m;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); } } int curi=0,curj=0; int totaltime=0; while(1) { int max=0; int x=curi; int y=curj; for(i=1;i<=m;i++) { for(j=0;j<n;j++) { if(max<a[i][j]) { max=a[i][j]; curi=i; curj=j; } } } if(x==0) //在路上的时候直接移动到curj列 不用计算时间 y=curj; if(totaltime+abs(curi-x)+abs(curj-y)+1+curi<=k) { sum+=max; totaltime+=abs(curi-x)+abs(curj-y)+1; a[curi][curj]=-1; x=curi; //x,y重新赋值 y=curj; } else { cout<<sum<<endl; break; } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator