• SDNU 1110.The Little Girl who Picks Mushrooms(思维)


    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

    Source

    思路:这道题难就难在题意难读。
          如果n<5,则可以随意采任意的蘑菇,如样例1中的1  9,就是随意采。还有就是1024的倍数也可能是0。
          如果 0<=n && n<=3,则肯能能随意采,那就把0g的东西给那三个仙女,然后再自己留着1024g,不给那个魔女。
          如果n == 4,(1)暴力搜索任意三框蘑菇,如果有任意三框的蘑菇加起来等于1024的倍数,则剩下两框可以随意采,让自己的重量达到1024,此时直接输出1024即可。(2)如果没有任意三框的蘑菇等于1024的倍数,则认为它是随意采的(即把前三框凑够1024的倍数),然后暴力搜索剩下两框,看它被魔女偷呀偷之后还剩多少。
          如果n == 5,则暴力搜索任意三框的蘑菇重量,如果为1024的倍数,则计算被魔女偷了之后还剩多少蘑菇;否则被仙女拿走所有蘑菇,输出0;
    #include <cstdio>
    #include <iostream>
    #include <string>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    #include <map>
    #include <vector>
    using namespace std;
    
    #define ll long long
    
    int n, bag[8], sum, ans;
    
    int main()
    {
        while(~scanf("%d", &n))
        {
            sum = 0;
            ans = 0;
            for(int i = 0; i<n; i++)
            {
                scanf("%d", &bag[i]);
                ans += bag[i];
            }
            if(0 <= n && n <= 3)
            {
                printf("1024
    ");
            }
            else if(n == 5)
            {
                for(int i = 0; i<n; i++)
                    for(int j = i+1; j<n; j++)
                        for(int k = j+1; k<n; k++)
                            if((bag[i]+bag[j]+bag[k])%1024 == 0)
                            {
                                int tmp = ans-(bag[i]+bag[j]+bag[k]);
                                while(tmp>1024)tmp -= 1024;
                                if(tmp>sum)sum = tmp;
                            }
                printf("%d
    ", sum);
            }
            else if( n == 4)
            {
                for(int i = 0; i<n; i++)
                    for(int j = i+1; j<n; j++)
                        for(int k = j+1; k<n; k++)
                            if((bag[i]+bag[j]+bag[k])%1024 == 0)
                            {
                                sum = 1024;
                            }
                if(sum>0)
                {
                    printf("%d
    ", sum);
                    continue;
                }
                for(int i = 0; i<n; i++)
                    for(int j = i+1; j<n; j++)
                    {
                        int tmp = bag[i]+bag[j];
                        while(tmp>1024)tmp -= 1024;
                        if(tmp>sum)sum = tmp;
                    }
                printf("%d
    ", sum);
            }
        }
        return 0;
    }
  • 相关阅读:
    js 数组相减
    js 对象数组去重
    vue 首次不触发watch的解决方法
    "神药"推荐--紫花地丁
    openstack 平台添加 nvidia vGPU
    string易错点整理总结
    CentOS安装图形界面
    CentOs安装ssh和scp
    数组把0移到末尾
    Windows下Celery安装与下使用
  • 原文地址:https://www.cnblogs.com/RootVount/p/10946425.html
Copyright © 2020-2023  润新知