武汉科技大学计算机学院11月月赛:The Little Girl who Picks Mushrooms

来源:互联网 发布:数据的重要性的名言 编辑:程序博客网 时间:2024/05/17 02:56

The Little Girl who Picks Mushrooms

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


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
194512 512 512 5125100 200 300 400 5005208 308 508 708 1108

Sample Output

102410240792

 

 

题意:

你有5个袋子去5座山上采蘑菇,每个袋子采对应山上采到的蘑菇。如果没有给出第n座山的采蘑菇数,那么你可以采任意数量的蘑菇。

但是,有如下难题:

1、有三个无赖要拿你的三袋蘑菇,并且这三袋蘑菇共和要是1024的倍数(0也可以),如果不满足,这三个无赖将那走你全部的蘑菇。

2、还有个人每次要拿你剩下的1024个蘑菇,直到你剩下的蘑菇数小于等于1024.

问:最后你还剩下多少蘑菇。

 

 

#include<iostream>#include<cstdio>#include<cmath>#include<cstdlib>#include<cstring>#include<string>#include<queue>using namespace std;int main(){    int i,j,k,n,a[6],sum;    while(cin>>n)    {        sum=0;        for(i=1;i<=n;i++)        {            scanf("%d",&a[i]);            sum+=a[i];        }        if(n<=3)//小于等于3时直接1024.至少有两个可变蘑菇数,一定可凑成两个1024的倍数        {            printf("1024\n");            continue;        }        if(n==4)//等于4时两种情况        {            int max1=0,flag=0;            for(i=1;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)                            flag=1;                    }            if(flag)//当其中有3袋是1024的整数倍时直接1024,另一袋和剩下可变蘑菇数一定可以组成1024的倍数            {                printf("1024\n");                continue;            }            else//否则输出两袋模1024的最大值,因为另两袋和剩下可变蘑菇数一定可以组成1024的倍数            {                for(i=1;i<=4;i++)                {                    for(j=i+1;j<=4;j++)                    {                        int t=a[i]+a[j];                        int temp=t%1024;                        if(temp==0&&t)                            temp=1024;                        if(temp>max1)                            max1=temp;                    }                }                printf("%d\n",max1);                continue;            }        }        //5袋时        int flag=0,max1=0;        for(i=1;i<=5;i++)            for(j=i+1;j<=5;j++)                for(k=j+1;k<=5;k++)                {                    int t=a[i]+a[j]+a[k];                    int left=sum-t,temp=t%1024;                    int k=left%1024;                    if(k==0&&left)                        k=1024;                    if(temp==0)                    {                        flag=1;                        if(max1<k)                            max1=k;                    }                }        if(flag)//有三代可以组成1024的倍数,输出剩下两袋模1024的最大值            printf("%d\n",max1);        else//任意三代都不是1024的整数倍,直接输出0            printf("0\n");    }    return 520;}


 

原创粉丝点击