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

Re:不会吧 好不容易出来了 又超时!!!!!!!!!!1

Posted by vince4053040 at 2009-12-23 15:25:32 on Problem 1928
In Reply To:不会吧 好不容易出来了 又超时!!!!!!!!!!1 Posted by:vince4053040 at 2009-12-23 15:25:22
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n,m,k,max,pp,N;
	int step,sum;
	int i,j,x_1,x_2,y_1,y_2;
	int a[56][56];
	cin>>N;
	while(N--)
	{
	cin>>n>>m>>k;
	max=0;
	step=k-2;
	sum=0;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			scanf("%d",&a[i][j]);
			if(a[i][j]>max)
			{
				max=a[i][j];
				x_1=i;
				y_1=j;
			}
		}
	}
	sum+=a[x_1][y_1];
	//cout<<x_1;
	//cout<<a[x_1][y_1];
	a[x_1][y_1]=0;
	step -= 2 * (x_1 + 1);  //天呐  X Y都分不清
	//cout<<step;

	x_2 = x_1; //为下面开始step值不变作保证
	//cout<<x_2;
	if(step<0)
	{
		cout<<0<<endl;
	}
	
	
	else{
		max=0;
		//cout<<step;
		//cout<<x_2;
		//cout<<x_1<<" "<<y_1;
		while(step>0)
		{
			max=0;
			step += x_2 + 1;// + 1;    //把多减的部分加回来
			//cout<<step<<" ";
			for(i=0;i<n;i++)
			{
				for(j=0;j<m;j++)
				{
					if(a[i][j]>max)
					{
						max=a[i][j];
						x_2=i;
						y_2=j;
						//cout<<max<<" ";
					}
				}
			}
			sum+=max;
			//cout<<sum<<" ";
			//cout<<a[x_2][y_2]<<" ";
			pp=a[x_2][y_2]; //最后减去用
			a[x_2][y_2]=0;
			step -= (abs(x_2 - x_1) + abs(y_2 - y_1) + x_2 + 1);// + 1;
			x_1 = x_2;
			y_1 = y_2;
		}
		cout<<sum - pp<<endl;
	}
	}


	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