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

## 求大神帮渣渣找找错误，讨论区的数据测试了都没错，可是提交一直wa

Posted by xia842655187 at 2016-07-22 14:04:19 on Problem 1042
```#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: