ZOJ 3657 The Little Girl who Picks Mushrooms 第37屆ACM/ICPC長春賽區現場賽C題(水題)

來源:互聯網
上載者:User
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
194512 512 512 5125100 200 300 400 5005208 308 508 708 1108
Sample Output
102410240792
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

 

此題比較坑爹。。。一開始一直沒有理解題意,不知道第一個範例是怎麼來的。。。。

理解錯誤了。

現場比賽的時候,我先是做了K,然後做完B。隊友一直再看這題,理解不過來。

然後我再看的這個C題。。。重新讀了幾遍題意。才理解過來。原來是5座山,現在只是完成了n個山。

然後迅速寫過這題。。。。。這題是封榜後AC的。。。導致其他題就沒有時間去做了。。。杯具啊。

 

n=0,1,2,3時,答案就是1024,很簡單。

n=5的時候,枚舉三個,讓三個的和是1024的倍數,然後求解最大值。

n=4時:

首先是要枚舉三個,看有沒有三個是1024的倍數,如果有答案就是1024了。。。(估計很多隊伍沒有做這種情況)。

然後再枚舉兩個找最大。

 

 

#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>using namespace std;int a[6];int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        int sum=0;        for(int i=0;i<n;i++)        {            scanf("%d",&a[i]);            sum+=a[i];        }        if(n>=0&&n<=3)        {            printf("1024\n");            continue;        }        int ans=0;        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++)                if((a[i]+a[j]+a[k])%1024==0)                 {                     int temp=sum-a[i]-a[j]-a[k];                     while(temp>1024)temp-=1024;                     if(temp>ans)ans=temp;                 }            printf("%d\n",ans);            continue;        }        if(n==4)        {            ans=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)                  {                      ans=1024;                  }            if(ans>0)            {                printf("1024\n");                continue;            }            for(int i=0;i<4;i++)              for(int j=i+1;j<4;j++)              {                  int temp=a[i]+a[j];                  while(temp>1024)temp-=1024;                  if(temp>ans)ans=temp;              }            printf("%d\n",ans);            continue;        }    }    return 0;}

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.