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

这是我的代码,我考虑了全0的情况,但是WR,请指教!

Posted by xtu722 at 2007-07-18 21:02:30 on Problem 1042
#include "iostream"

using namespace std;

#define Maxlen	200

int	n,h,fi[Maxlen],di[Maxlen],ti[Maxlen];
int	FishTmp,TmpF[Maxlen],FishRes,ResF[Maxlen];

int	Init()
{
	int	tmp,j;
	cin>>n;
	if(n&&n>0&&n<10000){
		cin>>h;
		for (j=0;j<n;j++)
			cin>>fi[j];
		for (j=0;j<n;j++)
			cin>>di[j];
		for (j=0;j<n-1;j++)		
			cin>>ti[j];	
		FishRes=-1;
		for (j=0;j<n;j++)
		{
			ResF[j]=0;
		}
		return 1;
	}
	else
		return 0;
}

void GetFish(int lt,int i)
{
	int	j=0,k,l;
	FishTmp=0;
	for (j=0;j<n;j++)
	{
		TmpF[j]=0;
	}
	j=0;
	for (l=0;l<lt;l++)
	{		
		for(k=0;k<i;k++){
			if(fi[j]-di[j]*TmpF[j]<fi[k]-di[k]*TmpF[k]&&fi[j]>=di[j]*TmpF[j]&&fi[k]>=di[k]*TmpF[k])
				j=k;	
		}
		
		if (fi[j]-di[j]*TmpF[j]>0)
		{
			FishTmp+=fi[j]-di[j]*TmpF[j];
		}
		TmpF[j]++;
	}
}


void Done()
{
	int	i,j;
	int	LeftTime;
	LeftTime=h*12;
	for (i=0;i<n;i++)
	{
		LeftTime=h*12;
		for (j=i+1;j>1;j--)
			LeftTime-=ti[j-2];	
		if (LeftTime<0)
			break;
		GetFish(LeftTime,i+1);
		if (FishTmp>FishRes)
		{
			FishRes=FishTmp;
			j=0;
			for(j=0;j<n;j++)
			ResF[j]=TmpF[j];
		}
	}
}

int main()
{
	int i;
	while (Init())
	{
		Done();
		
		for (i=0;i<n-1;i++)
		{
			cout<<ResF[i]*5<<", ";
		}
		cout<<ResF[i]*5<<endl;
		cout<<"Number of fish expected: "<<FishRes<<endl<<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