zoukankan      html  css  js  c++  java
  • HDU 4422 采蘑菇的小女孩

    The Little Girl who Picks Mushrooms
    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 2600    Accepted Submission(s): 828


    Problem Description
    It'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 Gensokyo. People in Gensokyo believe that 1 kilogram is equal to 1024 grams.
     

    Input
    There 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.
     

    Output
    For each test case, output the maximum possible amount of mushrooms Alice can bring home, modulo 20121014 (this is NOT a prime).
     

    Sample Input

    1
    9
    4
    512 512 512 512
    5
    100 200 300 400 500
    5
    208 308 508 708 1108

     

    Sample Output

    1024
    1024
    0
    792
    Hint

    In 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 and
    Star. 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)=1024

    2.Stolen by Marisa: ((708+1108)-1024)=792


    题意,采蘑菇的小女孩可以采5座山,输入第一个数是已经采的山,一个山装一个篮子,剩下山随便采来满足自己需要,因为有三个小精灵要想小女孩要三篮蘑菇,且必须是1024的倍数,如果送不了,则把蘑菇全部拿走,还要经过女巫的偷蘑菇流程,就是对1024取模,还有一个就是注意也可以送小精灵三个0,比如采5个山,分别是1024,0,0,0,0,则送小精灵的是三个0,这样才能保证进入深林得到最大蘑菇数。最后输出的就是进入能采得的蘑菇的最大数。看到这个题目当时就有点熟悉,因为这个题的规则和我们小时候玩的扑克斗牛游戏非常类似啊,具体规则传送门扑克斗牛技巧

    好了理解题意这道题就简单了,以后也不要小看模拟了,做出这道题的队并不多,别说这题那题水不想做了,不要做眼高手低的事,模拟有时候要考虑的情况很多,有时候就可能你卡在那道平时你瞧不起的题上。

    开始if语句中间有一个分号没去掉没看错来,无线WA,看来要仔细啊


    #include<cstdio>
    #include<iostream>
    
    using namespace std;
    
    int main()
    {
        int n;
        while(scanf("%d", &n)!=EOF)
            {
                //依次多情况考虑
               int i=0,j=0,k=0;
                if(n <= 3)//小于三篮则可以从另外山补充,最大可以采1024
                {
                    while(n--)
                    {
                        int a;
                       cin>>a;
                    }
                    cout<<1024<<endl;
                }
                else if(n == 4)
                {
                    int a[4];
                    for( i = 0; i < 4; i++)
                        scanf("%d", &a[i]);
                    int ans = 0;
                    for( i = 0; i < 4; i++)
                        for( j = i + 1; j < 4; j++)
                            for( k = j + 1; k < 4; k++)
                                if((a[i] + a[j] + a[k]) % 1024 == 0)
                                    ans = 1024;
                    if(ans == 0)//任意三篮给不了则要从最后的一座山来采做补充一定能过
                        for( i = 0; i < 4; i++){
                            for( j = i + 1; j < 4; j++){
                               if(ans<=((a[i] + a[j] - 1) % 1024 + 1))//一个小技巧,对剩下任意两篮取最大的,要保留最大为1024倍数的情况,如1024的最后得1024,1025的最后得1
                                  ans=(a[i] + a[j] - 1) % 1024 + 1;
                        }
                        }
                    cout<<ans<<endl;
    
                }
                else
                {
                    int a[5];
                    int sum = 0;
                    for( i = 0; i < 5; i++)
                    {
                       cin>>a[i];
                        sum += a[i];
                    }
                    int ans = 0;
                    for( i = 0; i < 5; i++){
                        for( j = i + 1; j < 5; j++){
                            for( k = j + 1; k < 5; k++){
    
                                if((a[i] + a[j] + a[k]) % 1024 == 0)
                                    if(ans<=((sum - a[i] - a[j] - a[k] - 1) % 1024 + 1))
                                       ans=(sum - a[i] - a[j] - a[k] - 1) % 1024 + 1;
                            }
                        }
                    }
                    cout<<ans<<endl;
                }
            }
            return 0;
        }
    
    
    


  • 相关阅读:
    【软件工程实践 · 团队项目】 第一次作业
    课下作业2
    实验三 敏捷开发与XP实践
    2017-2018-1 20155315 《信息安全系统设计基础》第11周学习总结
    2017-2018-1 20155315 《信息安全系统设计基础》实验四 外设驱动程序设计
    20155306 20155315 《信息安全技术》实验四、木马及远程控制技术
    2017-2018-1 20155315 《信息安全系统设计基础》第9周学习总结
    2017-2018-1 20155315 《信息安全系统设计基础》实验三 实时系统
    2017-2018-1 20155315 《信息安全系统设计基础》加分作业:实现mypwd
    2017-2018-1 20155315 《信息安全系统设计基础》第8周学习总结
  • 原文地址:https://www.cnblogs.com/mingrigongchang/p/6246226.html
Copyright © 2011-2022 走看看