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

## 可能比较好理解的贪心···

Posted by 947186602 at 2020-09-19 19:59:24 on Problem 2709 and last updated at 2020-09-19 20:00:53
```/**

**/
#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;
int num[15],N;

int main(){
while(~scanf("%d",&N) && N != 0){
int max_i = 0;
for(int i = 0;i < N;++i){
scanf("%d",num+i);
max_i = max_i > num[i] ? max_i : num[i];
}
scanf("%d",num+N);
int res = (max_i + 49) / 50;
for(int i = 0;i < N;++i){
num[i] = res * 50 - num[i];
}
while(num[N] > 0){
sort(num,num+N);
if(num[N-3] == 0){
for(int i = 0;i < N;++i)
num[i] += 50;
res++;
}
if(N > 3 && num[N-4] != 0){  //每次从最大的三种颜色里取 第三大变为第四大的量+1(避免第3第4大相等,dead loop)
//printf("before: %d %d %d %d\n",num[N-4],num[N-3],num[N-2],num[N-1]);
num[N-1] -= num[N-3] - num[N-4] + 1;
num[N-2] -= num[N-3] - num[N-4] + 1;
num[N] -= num[N-3] - num[N-4] + 1;
num[N-3] = num[N-4] - 1;
//printf("after: %d %d %d %d\n",num[N-4],num[N-3],num[N-2],num[N-1]);

}else{
num[N-1] -= num[N-3];
num[N-2] -= num[N-3];
num[N] -= num[N-3];
num[N-3] = 0;
}
}
printf("%d\n",res);
}
return 0;
}
```

Followed by: