zoukankan      html  css  js  c++  java
  • ZOJ 3657 The Little Girl who Picks Mushrooms 第37届ACM/ICPC长春赛区现场赛C题(水题)

    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

    此题比较坑爹。。。一开始一直没有理解题意,不知道第一个样例是怎么来的。。。。

    理解错误了。

    现场比赛的时候,我先是做了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;
    }
    人一我百!人十我万!永不放弃~~~怀着自信的心,去追逐梦想
  • 相关阅读:
    Big Data 應用:第二季(4~6月)台湾地区Game APP 变动分布趋势图
    大数据应用:五大地区喜新厌旧游戏APP类别之比较与分析
    Big Data應用:以"玩家意見"之數據分析來探討何謂"健康型線上遊戲"(上)
    Example:PanGu分詞系統-批次匯入新詞
    C#数据类型02--结构
    C#数据类型01--数组
    C#基础知识点
    陌生Layout属性
    LinearLayout(线性布局)
    Android--入门常识
  • 原文地址:https://www.cnblogs.com/kuangbin/p/2725626.html
Copyright © 2011-2022 走看看