Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一次ac。附上代码。参考。大牛直接忽视即可

Posted by zhangkeabcd at 2010-08-02 11:49:32 on Problem 1928
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator