hdu 4422 The Little Girl who Picks Mushrooms(水题)
来源:互联网 发布:淘宝简易射影棚 编辑:程序博客网 时间:2024/06/05 12:40
The Little Girl who Picks Mushrooms
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3168 Accepted Submission(s): 1037
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.
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.
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
102410240792HintIn 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 andStar. 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)=10242.Stolen by Marisa: ((708+1108)-1024)=792
题意:alice去五座山上采蘑菇,每座山采蘑菇的数量范围都是0 ≤ w i ≤ 2012。当采完蘑菇后,alice要恰好拿出三袋来且三袋的蘑菇数总和为1024的整数倍。否则,蘑菇清零。剩下的两袋蘑菇数量如果大于1024,巫婆会取走1024个蘑菇直到袋里的蘑菇不足1024,问alice最大能带多少蘑菇回家?
思路:可以推出如果n(n<=3),那么alice总有办法能将恰好3袋为1024整数倍且剩下来袋能为1024。所以只需要考虑n=4和n=5的这两种情况了。
n=5时,用三个for来枚举出所有的情况,取最大的就行了。
n=4时,有两种取法。一种是取两袋确定的一袋不确定的,因为可以取的范围是0~2012,2012>1024,所以一定有办法能让三袋恰好达到1024整数倍。剩下的再根据规则算就好。
另一种是取三袋确定的,只需在这确定四袋中枚举三袋讨论所有情况,如果有达标的,那么最后就可以得到1024个蘑菇。
注意:0也是1024的整数倍。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;const int mod=20121014;bool cmp(int a,int b){ return a<b;}int main(){ int n; while(~scanf("%d",&n)) { int a[10]; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); } if(n<=3) printf("%d\n",1024); else if(n==4) { int maxn=0; for(int i=1;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) { maxn=1024; } } } } for(int i=1;i<=4;i++) { for(int j=i+1;j<=4;j++) { int sum=a[i]+a[j]; while(sum>1024) { sum-=1024; } if(sum>maxn) maxn=sum; } } printf("%d\n",maxn); } else { int maxn=0; for(int i=1;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 sum=0; for(int l=1;l<=5;l++) { if(l!=i&&l!=j&&l!=k) sum+=a[l]; } while(sum>1024) { sum-=1024; } if(sum>maxn) maxn=sum; } } } } printf("%d\n",maxn); } } return 0;}
阅读全文
0 0
- hdu 4422 The Little Girl who Picks Mushrooms(水题)
- HDU 4422 The Little Girl who Picks Mushrooms【水题】
- hdu(4422)The Little Girl who Picks Mushrooms
- HDU 4422 The Little Girl who Picks Mushrooms(数学)
- HDU 4422 The Little Girl who Picks Mushrooms(模拟)
- The Little Girl who Picks Mushrooms HDU
- The Little Girl who Picks Mushrooms(HDU
- The Little Girl who Picks Mushrooms HDU
- hdu 4422 The Little Girl who Picks Mushrooms
- hdu 4422The Little Girl who Picks Mushrooms
- hdu 4422 The Little Girl who Picks Mushrooms
- Hdu 4422 The Little Girl who Picks Mushrooms
- HDU 4422 The Little Girl who Picks Mushrooms(模拟)
- hdu 4422——The Little Girl who Picks Mushrooms
- 【瞎搞】 HDU 4422 The Little Girl who Picks Mushrooms
- HDU 4422 The Little Girl Who Picks Mushrooms
- The Little Girl who Picks Mushrooms
- HDUOJ4422 The Little Girl who Picks Mushrooms
- 作业4
- Intellij idea实时响应修改的文件
- 糗事百科实例:
- C#实现 单点登录(SSO)(附源码)
- linux中SELINUX初识
- hdu 4422 The Little Girl who Picks Mushrooms(水题)
- [Jsoup]使用Jsoup消除不受信任的HTML (防止XSS攻击)
- Hibernate 异常日志
- 欢迎使用CSDN-markdown编辑器
- 彻底理解数字图像处理中的卷积-以Sobel算子为例
- 多线程糗事百科案例
- use a data or computed property based on the prop's value.
- React
- 安卓 onCreate 方法获取 view 宽高的方法