HDU 4422 The Little Girl who Picks Mushrooms (mathematics)

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 4422


Problem DescriptionIt's yet another festival season in Gensokyo. little girl Alice planned to pick mushrooms in five mountains. she brought five bags with her and used different bags to collect mushrooms from different mountains. each bag has a capacity of 2012 grams. alice has finished picking mushrooms in 0 ≤ n ≤ 5 mountains. in the I-th mountain, she picked 0 ≤ wi ≤ 2012 grams of mushrooms. now she is moving forward to the remained mountains. after finishing picking mushrooms in all the five mountains, she want to bring as much mushrooms as possible home to cook a delicious soup.
Alice lives in the forest of magic. at the entry of the forest of magic, live three mischievous fairies, Sunny, Lunar and Star. on Alice's way back home, to enter the forest, she must give them exactly three bags of mushrooms whose total weight must be of integral kilograms. if she cannot do so, she must leave all the five bags and enter the forest with no mushrooms.
Somewhere in the forest of magic near Alice's house, lives a magician, Marisa. marisa will steal 1 kilogram of mushrooms repeatedly from Alice until she has no more than 1 kilogram mushrooms in total. so when Alice gets home, what's the maximum possible amount of mushrooms Alice has? Remember that our common sense doesn't always hold in gensoft-. People in gensoft-believe that 1 kilogram is equal to 1024 grams.
 
InputThere are about 8192 test cases. Proceed to the end of file.
The first line of each test case contains an integer 0 ≤ n ≤ 5, the number of mountains where Alice has picked mushrooms. the second line contains n integers 0 ≤ wi ≤ 2012, the amount of mushrooms picked in each mountain.
 
OutputFor each test case, output the maximum possible amount of mushrooms Alice can bring home, modulo 20121014 (this is NOT a prime ).
Sample Input
194512 512 512 5125100 200 300 400 5005208 308 508 708 1108
 
Sample Output
102410240792HintIn the second sample, if Alice doesn't pick any mushrooms from the 5-th mountain. she can give (512 + 512 + 0) = 1024 grams of mushrooms to Sunny, Lunar andStar. marisa won't steal any mushrooms from her as she has exactly 1 kilogram of mushrooms in total. in the third sample, there are no three bags whose total weight is of integral kilograms. so Alice must leave all the five bags and enter the forest with no mushrooms. in the last sample: 1. giving Sunny, Lunar and Star: (208 + 308 + 508) = 10242. stolen by Marisa: (708 + 1108)-1024) = 792
 
Source2012 Asia ChangChun Regional Contest

Question:

There are a total of five mountains, each of which has a lot of mushrooms. A n is given to indicate that n of the mushrooms have been picked, and how many mushrooms can be taken back at most ..

After 5 mountains were picked, three people took the mushrooms from three bags. The number of mushrooms in these three bags was a multiple of 1024;

If the number of mushrooms in none of the three bags is sufficient, five bags are taken, that is, no mushroom is taken.

On the way home, someone steals mushrooms until the total number of mushrooms is no greater than 1024;

PS:

If n is less than or equal to 3, it will surely take 1024 of the mushrooms home!

If n is greater than 3, the classification is discussed!

The code is as follows:

# Include <cstdio> # include <cstring> int main () {int a [7]; int t; int n; while (~ Scanf ("% d", & n) {int sum = 0; for (int I = 0; I <n; I ++) {scanf ("% d ", & a [I]); sum + = a [I];} if (n <= 3) {printf ("1024 \ n"); continue ;} int maxx = 0, tt = 0; if (n = 4) {int flag = 0; for (int I = 0; I <4; I ++) {for (int j = I + 1; j <4; j ++) {for (int k = j + 1; k <4; k ++) {if (a [I] + a [j] + a [k]) % 1024 = 0) {flag = 1 ;}}} if (flag) {printf ("1024 \ n"); continue;} for (int I = 0; I <4; I ++) {for (int j = I + 1; j <4; j ++) {tt = a [I] + a [j]; while (tt> 1024) tt-= 1024; if (tt> maxx) {maxx = tt ;}} printf ("% d \ n", maxx); continue;} if (n = 5) {for (int I = 0; I <5; I ++) {for (int j = I + 1; j <5; j ++) {for (int k = j + 1; k <5; k ++) {int ss = a [I] + a [j] + a [k]; if (ss % 1024 = 0) {tt = sum-ss; while (tt> 1024) tt-= 1024; if (tt> maxx) {maxx = tt ;}}} printf ("% d \ n ", maxx) ;}} return 0 ;}


HDU 4422 The Little Girl who Picks Mushrooms (mathematics)

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.