| ||||||||||
| 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#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
int t[50] = {0};
int h,n;
int ans[50];
int ans_n;
int ans_sum;
struct Lake
{
int can;
int dec;
int num;
}lake[50];;
bool cmp(Lake A,Lake B)
{
if(A.can == B.can && A.dec == B.dec)
return A.num < B.num;
else if(A.can == B.can)
return A.dec < B.dec;
return A.can > B.can;
}
void Output()
{
for(int i = 0;i < n;i++)
{
if(i != 0)
printf(", ");
printf("%d",ans[i] * 5);
}
printf("\nNumber of fish expected: %d\n",ans_sum);
}
void greedy(int pos,int time)
{
int fish[50];
int Time[50];
memset(fish,0,sizeof(fish));
memset(Time,0,sizeof(Time));
if(time <= 0)
return;
Lake copy_lake[50];
memset(copy_lake,0,sizeof(copy_lake));
int sum = 0;
for(int i = 0;i < n;i++)
{
copy_lake[i] = lake[i];
}
for(int i = 0;i < time;i++)
{
sort(copy_lake,copy_lake + pos + 1,cmp);
if(copy_lake[0].can == 0)
{
Time[0]++;
continue;
}
fish[copy_lake[0].num] += copy_lake[0].can;
Time[copy_lake[0].num] ++;
sum += copy_lake[0].can;
copy_lake[0].can -= copy_lake[0].dec;
if(copy_lake[0].can < 0)
copy_lake[0].can = 0;
}
if(sum > ans_sum)
{
for(int i = 0;i <= pos;i++)
{
ans[i] = Time[i];
}
ans_sum = sum;
}
}
void Solve()
{
for(int i = 0;i < n;i++)
{
h -= t[i];
greedy(i,h);
}
Output();
}
void Input()
{
bool flag = 0;
while(cin >> n && n)
{
if(flag)
printf("\n");
flag = 1;
ans_sum = -1;
memset(ans,0,sizeof(ans));
memset(lake,0,sizeof(lake));
memset(t,0,sizeof(t));
cin >> h;
h = h * 12;
ans[0] = h;
for(int i = 0;i < n;i++)
{
scanf("%d",&lake[i].can);
if(lake[i].can < 0)
lake[i].can = 0;
lake[i].num = i;
}
for(int i = 0;i < n;i++)
{
scanf("%d",&lake[i].dec);
}
for(int i = 1;i < n;i++)
{
scanf("%d",&t[i]);
}
Solve();
}
}
int main()
{
Input();
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator