Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

贴一个AC的代码

Posted by zxj1015 at 2013-10-13 12:46:31 on Problem 1042
#include <iostream>
#include <fstream>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
//*******************************************************************
int f[30]={0};
int d[30]={0};
int t[30]={0};
int cur[30]={0};
//*********************************************************************
int main()
{
while(true)
{
int n=0,h=0;
cin>>n;
if(n==0)
break;
cin>>h;
h=h*12;
for(int i=0;i<n;++i)
cin>>f[i];
for(int i=0;i<n;++i)
cin>>d[i];
for(int i=0;i<n-1;++i)
cin>>t[i];
int mmax=-1;
for(int i=0;i<n;++i)
{
int sum=0;
int temp[30]={0};
int t1=0;
for(int j=0;j<i;++j)
t1+=t[j];
int hh=h-t1;
//if(i==1)
//	cout<<"fuck:-"<<h<<endl;
for(int j=hh;j>0;--j)
{
int max=-1;
int index=-1;
for(int k=0;k<=i;++k)
{
if(f[k]-temp[k]*d[k]>max)
{
max=f[k]-temp[k]*d[k];
index=k;
}
}
if(max>0)
{
sum+=max;
temp[index]++;
}
else
{
temp[0]++;
}
}
if(sum>mmax)
{
mmax=sum;
for(int p=0;p<n;++p)
{
cur[p]=temp[p];
}
}
else if(sum==mmax)
{
int flag=0;
for(int p=0;p<n;++p)
{
if(cur[p]<temp[p])
{
flag=1;
break;
}
else if(cur[p]>temp[p])
{
flag=2;
break;
}
}
if(flag==1)
{
for(int p=0;p<n;++p)
{
cur[p]=temp[p];
}
}
}
}
for(int i=0;i<n-1;++i)
{
cout<<(5*cur[i])<<", ";
}
cout<<(5*cur[n-1])<<endl;
if(mmax<0)
mmax=0;
cout<<"Number of fish expected: "<<mmax<<endl;
cout<<endl;
}
return 0;
}


Followed by: