chedan541300521 于 2014.03.19 10:17 提问

#include
#include
#include
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int n;
while(cin>>n&&n!=0){
int hour;
int fi[30];
int di[30];
int ti[30];
int timid[30];

``````    cin>>hour;
int max;
for(int i=0;i<n;i++)
cin>>fi[i];
for(int i=0;i<n;i++)
cin>>di[i];
for(int i=0;i<n-1;i++)
cin>>ti[i];
int maxfish=0;
int lakenum=0;
int sum=0;
int time=1;
//  fimid初始化
hour*=12;
int hourmid=hour;
int summid=0;
int timemid[30];
int timemid2[30];
int fimid[30];

for(int i=0;i<n;i++)
{
memcpy(&fimid,&fi,sizeof(fi));
memset(&timemid,0,sizeof(timemid));
for(int j=0;j<i;j++)
{
hour-=ti[j];
}
while(hour>0){

for(int j=0;j<i+1;j++)            //枚举 为了排除路上时间带来的干扰，为贪心创下条件
{
if(fimid[j]>maxfish)
{
maxfish=fimid[j];
lakenum=j;

}
}
if (maxfish==0)
{timemid[0]+=hour;
hour=0;
}
else{
timemid[lakenum]++;
sum+=maxfish;
fimid[lakenum]-=di[lakenum];
if(fimid[lakenum]<0)  fimid[lakenum]=0;
hour-=time;
maxfish=0;
``````

}
}
hour=hourmid;

if(sum>summid) {

``````     summid=sum;
for(int j=0;j<n;j++)
{
timemid2[j]=timemid[j];
}

}
sum=0;
}
for(int j=0;j<n;j++)
{
if(j!=0) cout<<", ";
cout<<5*timemid2[j];
}
cout<<endl;
cout<<"Number of fish expected: "<<summid<<endl;

}
return 0;
``````

}