HDU 4422 The Little Girl who Picks Mushrooms(数学)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4422

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

Source

2012 Asia ChangChun Regional Contest

题意:

一共有5座山,每座山有很多的蘑菇,给出一个 n 表示已经采了 n 座山上的蘑菇,求最多带回去多少蘑菇。。

当采完5座山后,有三个人拿走三个袋子里的蘑菇,这三个的袋子的蘑菇数量为1024的倍数;

如果没有三个袋子的蘑菇数目满足情况,则拿走5个袋子,即不能带走任何蘑菇。

并且回家的路上有人偷蘑菇,一直偷,直到总蘑菇数不大于1024;

PS:

如果n小于等于3,那么一定能拿回家1024的蘑菇!

如果n大于3,则分类讨论!

代码如下:

#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;
}
时间: 2024-10-05 11:32:30

HDU 4422 The Little Girl who Picks Mushrooms(数学)的相关文章

HDU 4422 The Little Girl who Picks Mushrooms (2012年成都赛区现场赛C题)

1.题目描述:点击打开链接 2.解题思路:本题是一道简单模拟题,然而,自己的方法不对WA了很多次==.最后不得不弃用自己的思路了.首先用-1表示还没有使用过的位置.可以每次枚举3个位置,如果发现这3个位置中没有-1且他们的和不能被1024整除,那么return 0,否则,找到没有被标记的另外2个位置,如果这2个位置其中一个为-1,那么直接返回1024,因为我们已经交了三个袋子了,剩下的袋子中如果又没有确定的,那么一定可以凑成1024.否则,计算这2个位置的和,然后看减去若干次1024后剩下多少,

ZOJ 3657 The Little Girl who Picks Mushrooms

The Little Girl who Picks Mushrooms Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original ID: 365764-bit integer IO format: %lld      Java class name: Main It's yet another festival season in Gensokyo. Little girl Alic

hdu 2200 Eddy&#39;s AC难题(简单数学。。)

题意: N个人,每个人AC的题数都不一样. Eddy想从中选出一部分人(或者全部)分成两组.必须满足第一组中的最小AC数大于第二组中的最大AC数. 问共有多少种不同的选择方案. 思路: 简单数学.. 代码: ll C(int n,int x){ ll ans=1; rep(i,1,x){ ans = ans*(n+1-i)/i; } return ans; } int main(){ int n; while(cin>>n){ ll ans = 0; rep(i,2,n){ ans += (C

HDU 4952 Number Transformation 多校8 机智数学

哎.这个题想了好久,状态不对啊...一个大家都出的题..当时想到肯定是可以有什么规律来暴力,不用算到10的10次方 对于某个k,x.从1到k循环,每次求一个新的x,这个x要大于等于原x,并且要是i的倍数... 一直觉得有规律可循,后来知道就是倍数,我们设倍数为 b, 则b2*(i+1)>=b1*(i);可以知道b2>=b1-b1/(i+1),则,b2在b1小于等于i+1的时候便不会再变换,题目最大的倍数为10的10次方,根据第一个式子,最多经过10的五次方,倍数就会缩为10的五次方,此时i也&

POJ 3340 &amp; HDU 2410 Barbara Bennett&#39;s Wild Numbers(数学)

题目链接: PKU:http://poj.org/problem?id=3340 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2410 Description A wild number is a string containing digits and question marks (like 36?1?8). A number X matches a wild number W if they have the same length, and

HDU 4791 &amp; ZOJ 3726 Alice&#39;s Print Service (数学 打表)

题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5072 Problem Description Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using her pr

HDU - 4422-The Little Girl who Picks Mushrooms

题目链接:https://vjudge.net/problem/HDU-4422 题目大意: 自行百度 题目分析: 当n<=3的时候,易得可以得到的最多的蘑菇是1024. 当n>3时,可以进行分类讨论. 注意有两个莫名奇妙的毒点: 1.我用取模WA而用while不断相减AC 2.三个相加等于零的情况也可以通过 给出代码: 1 #include <cstdio> 2 #include <iostream> 3 #include <string> 4 #incl

状态压缩 UVALive 6068 The Little Girl who Picks Mushrooms (12长春C)

题目传送门 题意:采蘑菇.现在采了n座山,共5座山,最后要求有三个篮子的蘑菇量是1024的整数倍,丢掉后一直减1024直到不超过1024 分析:n <= 3时直接1024,否则状压枚举哪三个篮子丢弃,更新最值 /************************************************ * Author :Running_Time * Created Time :2015/10/28 星期三 19:21:49 * File Name :C.cpp *************

HDU 3296 &amp; POJ 3138 Acm Team Section(数学)

题目链接: HDU: http://acm.hdu.edu.cn/showproblem.php?pid=3296 POJ:  http://poj.org/problem?id=3138 Acm Team Section Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 159    Accepted Submission(s): 47