| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
不知道为什么,总是wa,看了帖子里说的全0等几种情况,运行都正确#include<iostream>
using namespace std;
int getMax( int f[], int n )
{
int max = 0;
for( int i = 0; i <= n; i++ )
if( f[max] < f[i] )
max = i;
return max;
}
bool haveFish( int f[], int n )
{
int flag = false;
for( int i = 0; i <= n; i++ )
if( f[i] > 0 )
{
flag = true;
break;
}
return flag;
}
bool better( int u1[], int u2[], int n )
{
for( int i = 0; i < n; i++ )
{
if( u1[i] < u2[i] )
return false;
if( u1[i] == u2[i] )
continue;
if( u1[i] > u2[i] )
return true;
}
return false;
}
int main()
{
int n;
cin >> n;
while( n != 0 )
{
int h;
cin >> h;
h *= 12;
int *f = new int[n];
int *d = new int[n];
int *t = new int[n];
int *m = new int[n];
int *cf = new int[n];
int **u = new int*[n];
for( int i = 0; i < n; i++ )
u[i] = new int[n];
for( int i = 0; i < n; i++ )
cin >> f[i];
for( int i = 0; i < n; i++ )
cin >> d[i];
t[0] = 0;
for( int i = 1; i < n; i++ )
{
cin >> t[i];
t[i] += t[i-1];
}
for( int i = 0; i < n; i++ )
m[i] = 0;
for( int i = 0; i < n; i++ )
for( int j = 0; j < n; j++ )
u[i][j] = 0;
for( int i = 0; i < n; i++ ) // the farest lake is i
{
int time = h - t[i];
if( time <= 0 )
continue;
for( int j = 0; j < n; j++ )
cf[j] = f[j];
while( (time > 0) && haveFish( cf, i ) )
{
int lake = getMax( cf, i );
m[i] += cf[lake];
cf[lake] -= d[lake];
if( cf[lake] < 0 )
cf[lake] = 0;
u[i][lake] += 1;
time -= 1;
}
if( time > 0 )
u[i][0] += time;
}
int max = 0;
for( int i = 0; i < n; i++ )
{
if( m[max] < m[i] )
max = i;
if( ( m[max] == m[i] ) && better( u[i], u[max], n ) )
max = i;
}
for( int i = 0; i < (n-1); i++ )
cout << u[max][i]*5 << ",";
cout << u[max][n-1]*5 << endl;
cout << "Number of fish expected: " << m[max] << endl;
delete[] f;
delete[] d;
delete[] t;
delete[] cf;
delete[] m;
for( int i = 0; i < n; i++ )
delete[] u[i];
delete[] u;
cin >> n;
if( n > 0 )
cout << endl;
}
system("pause");
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator