zoukankan      html  css  js  c++  java
  • HDU 4422 The Little Girl who Picks Mushrooms【水题】

    The Little Girl who Picks Mushrooms

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


    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

    n<=3时必定成立,不论数字多少都可以达到1024

      n==4时如果四个中有3个能够组成1024的倍数,则必为1024若不能则找四个里面的两个减去1024最大即可

    n==5的时候暴力枚举即可


    #include<iostream>	
    #include<algorithm>
    #include<cmath>
    #include<cstdio>
    #include<cstdlib>
    #include<queue>
    #include<map>
    #include<set>
    #include<stack>
    #include<bitset>
    #include<numeric>
    #include<vector>
    #include<string>
    #include<iterator>
    #include<cstring>
    #include<functional>
    #define INF 0x3f3f3f3f
    #define ms(a,b) memset(a,b,sizeof(a))
    using namespace std;
    
    const int maxn = 10010;
    const int mod = 1e9 + 7;
    const double pi = acos(-1.0);
    
    typedef pair<int, int> P;
    typedef long long ll;
    typedef unsigned long long ull;
    
    int a[10];
    
    int main()
    {
    	int n;
    	while (~scanf("%d", &n))
    	{
    		for (int i = 1; i <= n; i++) scanf("%d", a + i);
    		if (n <= 3)
    		{
    			puts("1024");
    			continue;
    		}
    		if (n == 5)
    		{
    			int ans = 0;
    			for (int i = 1; i <= 5; i++)
    			{
    				for (int j = 1; j <= 5; j++)
    				{
    					if (j != i)
    					{
    						for (int k = 1; k <= 5; k++)
    						{
    							if (k != j&&k != i)
    							{
    								if ((a[i] + a[j] + a[k]) % 1024 == 0)
    								{
    									for (int p = 1; p <= 5; p++)
    									{
    										if (p != i&&p != j&&p != k)
    										{
    											for (int q = 1; q <= 5; q++)
    											{
    												if (q != p&&q != i&&q != j&&q != k)
    												{
    													int temp = a[p] + a[q];
    													while (temp > 1024) temp -= 1024;
    													ans = max(temp, ans);
    												}
    											}
    										}
    									}
    								}
    							}
    						}
    					}
    				}
    			}
    			printf("%d
    ", ans);
    		}
    		else
    		{
    			int ans = 0;
    			bool flag = 0;
    			for (int i = 1; i <= 4; i++)
    			{
    				for (int j = 1; j <= 4; j++)
    				{
    					if (j != i)
    					{
    						for (int k = 1; k <= 4; k++)
    						{
    							if (k != j&&k != i)
    							{
    								if ((a[i] + a[j] + a[k]) % 1024 == 0)
    								{
    									ans = 1024;
    									flag = 1;
    									break;
    								}
    							}
    						}
    						if (flag) break;
    					}
    				}
    				if (flag) break;
    			}
    			if (!flag)
    			{
    				for (int i = 1; i <= 4; i++)
    				{
    					for (int j = 1; j <= 4; j++)
    					{
    						if (j != i)
    						{
    							int temp = a[i] + a[j];
    							while (temp > 1024) temp -= 1024;
    							ans = max(ans, temp);
    						}
    					}
    				}
    			}
    			printf("%d
    ", ans);
    		}
    	}
    }


    Fighting~
  • 相关阅读:
    1042 Shuffling Machine
    1043 Is It a Binary Search Tree
    1044 Shopping in Mars
    1443. Minimum Time to Collect All Apples in a Tree
    1045 Favorite Color Stripe
    Java笔记八:Java内置的包装类(1)
    Java笔记七:Java数字和日期处理(2)
    Java笔记六:Java数字和日期处理(1)
    Java笔记五: Java正则表达式
    Java笔记四:Java字符串处理
  • 原文地址:https://www.cnblogs.com/Archger/p/12774761.html
Copyright © 2011-2022 走看看