zoj The Little Girl who Picks Mushrooms

The Little Girl who Picks Mushrooms

Time Limit: 2 Seconds Memory Limit: 32768 KB

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 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, lives 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 get 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 belive that 1 kilograms is equal to 1024 grams.

Input

There are about 8192 test cases. Process 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
Note

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 kilograms 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:

  • Giving Sunny, Lunar and Star: (208+308+508)=1024
  • Stolen by Marisa: ((708+1108)-1024)=792 
第一大坑题,对于这题很明显的什么都 不是的水题 但是题意老是不明白,首先题目不把第 一个数据解释一下,搞的我们莫明其妙,对 于第一个数据,其实我们还是能发现点什么的,题目给的是,在几个山上采的,而对于其它的山上,是没有限制的,也就是这点,是很关键的,这点,搞清楚了,就什么都明白了!
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int a[5];
bool cmp(int a,int b)
{
    return a<b;
}
int main()
{
    int n,i,j,k,sum;
    while(scanf("%d",&n)!=EOF)
    {
      for(i=0;i<n;i++)
      {
          scanf("%d",&a[i]);
      }
      if(n<=3)
      {
          printf("1024\n");
          continue;
      }
      if(n==4)
      {
          if((a[0]+a[1]+a[2])%1024==0)
          {
              printf("1024\n");
              continue;
          }
           if((a[0]+a[1]+a[3])%1024==0)
          {
              printf("1024\n");
              continue;
          }
           if((a[0]+a[3]+a[2])%1024==0)
          {
              printf("1024\n");
              continue;
          }
           if((a[1]+a[3]+a[2])%1024==0)
          {
              printf("1024\n");
              continue;
          }
          int maxx=-1;
          for(i=0;i<3;i++)
          {
              for(j=i+1;j<4;j++)
              {
                  int  temp=(a[i]+a[j]);
                  while(temp>1024)
                  {
                      temp-=1024;
                  }
                  if(temp>maxx)
                  {
                      maxx=temp;
                  }

              }
          }
          printf("%d\n",maxx);
          continue;
      }
      else if(n==5){
        for(i=0,sum=0;i<5;i++)
        sum+=a[i];
        bool flag=true;
        int maxx=-1;
        int tempsum=sum;
        for(i=0;i<=2;i++)
        for(j=i+1;j<4;j++)
        for(k=j+1;k<5;k++)
        {
            if((a[i]+a[j]+a[k])%1024==0)
            {
                sum=tempsum;
                sum-=a[i]+a[j]+a[k];
                while(sum>1024)
            sum-=1024;
            if(sum>maxx)
            maxx=sum;

            }

        }

       if(maxx!=-1)
       {

            printf("%d\n",maxx);
       }
        else
            printf("0\n");


      }
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值