Question:
There are five mountains in total. Someone has five baskets to pick up mushrooms. Now he has picked several mushrooms on the mountains. You can decide the number of mushrooms on the following mountains. But he has to hand over three baskets, and their sum must be a multiple of 1024. Otherwise, the remaining two baskets will be handed over. Then, if the remaining quantity is greater than 1024, subtract 1024 until it is not greater. The maximum value remaining at the end of the question.
Solution:
I thought it was wrong to understand the question .. It turned out to be a pitfall .. When you hand in three baskets, their sum can be 0 ..
Post a simplified code.
[Cpp]
# Include <stdio. h>
# Include <algorithm>
Using namespace std;
Int n, a [6], sum, ans;
Bool mult (int x)
{
Return x % 1024 = 0;
}
Int calc (int x)
{
While (x> 1024)
X-= 1024;
Return x;
}
Void solve ()
{
For (int I = 0; I <n; I ++)
For (int j = I + 1; j <n; j ++)
If (n = 4 | mult (sum-a [I]-a [j])
Ans = max (ans, calc (a [I] + a [j]);
}
Int main ()
{
While (~ Scanf ("% d", & n ))
{
Sum = 0, ans = 0;
For (int I = 0; I <n; I ++)
{
Scanf ("% d", & a [I]);
Sum + = a [I];
}
If (n <= 3)
Ans = 1024;
Else
If (n = 4)
For (int I = 0; I <4; I ++)
If (mult (sum-a [I])
Ans = 1024;
If (ans! = 1024)
Solve ();
Printf ("% d \ n", ans );
}
Return 0;
}