• HDU 4422 The Little Girl who Picks Mushrooms ( 模拟)


    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
     

    题意难懂,懂了以后就是模拟的水题了。
    题意是去五座山采蘑菇,回来以后先给三个精灵共三袋蘑菇,其总数加起来要是1024的倍数。否则答案是0。如果给了精灵,剩下的蘑菇大于1024,则会被不停的偷走1024个,直到<=1024个。
    给了n座山的采蘑菇数量,如果n<5,则剩下的山可以采任意的a,0<a<2012。所以n<4时,至少一座山可以去采2012个,其他就选三个去凑1024倍数,所以一定能剩下1024个。
    n=4,如果其中三个可以组成1024倍数,则一定可以剩下1024个;如果不能,则要靠剩下那个没有采的山和采过的两座山来凑,所以剩下两座山,两个for来挑出剩下最大的那个组合。
    n=5,如果其中三个可以组成1024倍数,则剩下两个不断-1024就是答案,三个for挑选出最大的组合。如果组合不出1024倍数,则答案为0。
    然后就是考虑情况的时候要注意细节。不然因此WA很亏。
     
      1 #include <iostream>
      2 #include <cstdio>
      3 #include <cstring>
      4 #include <algorithm>
      5 #include <cctype>
      6 #include <cstdlib>
      7 #include<cmath>
      8 #include <string>
      9 #include <map>
     10 #include <set>
     11 #include <queue>
     12 #include <vector>
     13 #include <stack>
     14 #include <cctype>
     15 using namespace std;
     16 typedef unsigned long long ull;
     17 #define INF 0xfffffff
     18 
     19 
     20 int main()
     21 {
     22     int k,m,q,p;
     23     int T;
     24 
     25     int a[5],n;
     26 
     27     while(cin>>T)
     28     {
     29         for(int i=0;i<T;++i)
     30         {
     31             cin>>a[i];
     32         }
     33         if(T<4)
     34         {
     35             cout<<1024<<endl;
     36         }else if(T==4)
     37         {
     38             int ans=0;
     39             m=0;
     40             q=0;
     41             for(int i=0;i<T;++i)
     42             {
     43                 for(int j=i+1;j<T;++j)
     44                 {
     45                     for(int k=j+1;k<T;++k)
     46                     {
     47                         if((a[i]+a[j]+a[k])%1024==0)
     48                         {
     49                             m=1;                    
     50                         }
     51                     }
     52                 }
     53             }
     54             if(m)
     55             {
     56                 cout<<1024<<endl;
     57                 continue;
     58             }
     59             
     60             k=0;
     61             for(int i=0;i<T;++i)
     62             {
     63                 for(int j=i+1;j<T;++j)
     64                 {
     65                     p=a[i]+a[j];
     66                     while(p>1024)
     67                     {
     68                         p-=1024;
     69                     }
     70                     k=max(k,p);
     71                 }
     72             }
     73             cout<<k<<endl;
     74         }else if(T==5)
     75         {
     76             int ans=0;
     77             m=0;
     78             for(int i=0;i<3;++i)
     79             {
     80                 for(int j=i+1;j<4;++j)
     81                 {
     82                     for(int k=j+1;k<5;++k)
     83                     {
     84                         if((a[i]+a[j]+a[k])%1024==0)
     85                         {
     86                             m=1;
     87                             q=0;
     88                             for(p=0;p<5;++p)
     89                             {
     90                                 if(p!=i&&p!=j&&p!=k)
     91                                 {
     92                                     q+=a[p];
     93                                 }
     94                             }
     95                             
     96                             while(q>1024)
     97                             {
     98                                 q-=1024;
     99                             }    
    100                             ans=max(ans,q);                        
    101                         }
    102 
    103                     }
    104 
    105                 }
    106             }
    107             if(m)
    108             {
    109                 cout<<ans<<endl;
    110             }else
    111             {
    112                 cout<<0<<endl;
    113             }
    114         }
    115 
    116     }
    117     return 0;
    118 }
  • 相关阅读:
    添加配置分析
    day06 prometheus
    电话收藏
    xxljob客户端启动分析
    xxljob运行idea可以,生产环境不行
    Apoll创建项目分析
    xxljob后台admin管理端启动流程
    xxljob服务器端远程触发任务逻辑
    发布配置分析
    Java 线程池工作过程
  • 原文地址:https://www.cnblogs.com/Traveller-Leon/p/4871979.html
Copyright © 2020-2023  润新知