ZOJ 3657 The Little Girl who Picks Mushrooms (12-year Changchun semi-finals-C)

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.