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:无言..这样可以过

Posted by tamik at 2007-08-16 09:58:29 on Problem 1042
In Reply To:无言 Posted by:200530720224 at 2007-08-15 12:31:40
#include "iostream"
using namespace std;
#define big 27
main()
{
   //int cas;//n个事件
   int n;//n个湖
   int h;//h个小时
   int left=0;//现在剩下的时间

   int fi[big];//湖的初始钓总鱼量
   int di[big];//钓鱼量减小数
   int fn[big];//当前鱼量
   int fmax=0;//最大鱼量
   int sum=0;//所钓的鱼量
   int sumax=0;
   int fk=0;
   int ti[big];//湖之间的走路的时间
   int end[big];//记录在那个湖结束钓鱼的总时间
   int i,k;
   int take[big]={0};//每次的时间..这两个take都是为了输出而用的...对题目的求解没有用
   int taketime[big]={0};//最大的确定时间

   while(1){
	   left=0;
	   cin>>n;
	   if(n==0)break;
	   cin>>h;
	   h=h*60;//h为小时
	   for(i=0;i<n;i++)cin>>fi[i];
	   for(i=0;i<n;i++)cin>>di[i];
       end[0]=0;
	   for(i=0;i<n-1;i++){
		   cin>>ti[i];
	       end[i+1]=end[i]+ti[i]*5;
	   }
	   sumax=-1;
       for(i=0;i<n;i++){
		   left=h-end[i];
		   for(k=0;k<=i;k++){
			   fn[k]=fi[k];//初值
		       take[k]=0;
		   }
		   
		   while(left>0){
               fmax=fn[0];
			   for(k=0;k<=i;k++){
		         // if(fk==k)fn[k]=fn[k]-di[k];//上次钓了就减
				  
				  //if(fn[k]==0)continue;
				  if(fmax<fn[k]){
					  fmax=fn[k];//找之中的最大
				      fk=k;
				  }
			   }
			    
			   if(fmax==0)break;
			   sum+=fmax;
			   fn[fk]=fn[fk]-di[fk];//上次钓了就减
			   if(fn[fk]<0)fn[fk]=0;
			   //if(fmax<0)fmax=0;
			   left-=5;
			   take[fk]+=5;   
			   fk=0;
		   }
		   take[0]+=left;
		   //cout<<sum<<endl;
		   if(sumax<sum){
			   sumax=sum;
			   for(k=0;k<=i;k++){//改成<=i.就这么简单.可以过
		          taketime[k]=take[k];
			      take[k]=0;//清0,为下次用
			   }
		   }
                     //else if()不用这个........这样可以过了
		   sum=0;
		   fk=0;
	   }
	   for(k=0;k<n-1;k++){
	      cout<<taketime[k]<<", ";
		  taketime[k]=0;
	   }
	   cout<<taketime[k]<<endl;
	   taketime[k]=0;
       cout<<"Number of fish expected: "<<sumax<<endl;//所钓鱼的最大鱼量
	   cout<<endl;
   }
}

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