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

为什么这段代码过不了???疑惑中,注:不是我写的。。。只是讨论一下。。。

Posted by lbp at 2005-09-16 11:09:40 on Problem 1042
//按照lrj的书上的算法做的,减掉路程的时间后,每次选最大的钓鱼量;

#include<iostream>
#include<fstream>
#include<algorithm>

using namespace std;

int main()
{
    //ifstream cin("tmp.txt");
    int h,n,f[26],d[26],t[26];//max_lake=25;
    while(cin>>n && n!=0)
	{
        
        cin>>h;
        h*=12;//60=5*12;
        int i,j,k;
        for(i=0;i<n;i++){
            cin>>f[i];
        }
        for(i=0;i<n;i++){
            cin>>d[i];
        }
        t[0]=0;
        for(i=1;i<n;i++){
            cin>>t[i];
        }
/////////////////////////////////////input;;;
        int res[26]={0};
        int max_s=0;





        for(j=0;j<=n-1;j++){//j<n;
            int ff[26];
            for(i=0;i<26;i++){//初始值不变;
                ff[i]=f[i];
            }    
           
            h-=t[j];
            if(h<=0) break;
               
            int count[26] = {0};
            int s=0;
            int pos;   
            for(i=0;i<h;i++){
                int max_=ff[0];     //找最大元素
                pos=0; 
                for(k=0;k<=j;k++){
                    if( ff[k]>max_ ){
                        max_=ff[k];
                        pos=k;
                    }
                }        
                    
                s+=ff[pos];
                count[pos]++;    //计数
                ff[pos]-=d[pos];
                if( ff[pos] <=0 )ff[pos]=0;
            }

            if(max_s<s){
                max_s=s;
                for(i=0;i<n;i++){
                    res[i]=count[i];
                }
            }        
        }    

        for(i=0;i<n;i++){
            cout<<res[i]*5;
            if(i==n-1)cout<<endl;
            else cout<<",";
        }
        cout<<"Number of fish expected:"<<max_s<<endl;
        cout<<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