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很亏。
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include<cmath>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <stack>
#include <cctype>
using namespace std;
typedef unsigned long long ull;
#define INF 0xfffffff int main()
{
int k,m,q,p;
int T; int a[],n; while(cin>>T)
{
for(int i=;i<T;++i)
{
cin>>a[i];
}
if(T<)
{
cout<<<<endl;
}else if(T==)
{
int ans=;
m=;
q=;
for(int i=;i<T;++i)
{
for(int j=i+;j<T;++j)
{
for(int k=j+;k<T;++k)
{
if((a[i]+a[j]+a[k])%==)
{
m=;
}
}
}
}
if(m)
{
cout<<<<endl;
continue;
} k=;
for(int i=;i<T;++i)
{
for(int j=i+;j<T;++j)
{
p=a[i]+a[j];
while(p>)
{
p-=;
}
k=max(k,p);
}
}
cout<<k<<endl;
}else if(T==)
{
int ans=;
m=;
for(int i=;i<;++i)
{
for(int j=i+;j<;++j)
{
for(int k=j+;k<;++k)
{
if((a[i]+a[j]+a[k])%==)
{
m=;
q=;
for(p=;p<;++p)
{
if(p!=i&&p!=j&&p!=k)
{
q+=a[p];
}
} while(q>)
{
q-=;
}
ans=max(ans,q);
} } }
}
if(m)
{
cout<<ans<<endl;
}else
{
cout<<<<endl;
}
} }
return ;
}

HDU 4422 The Little Girl who Picks Mushrooms ( 模拟)的更多相关文章

  1. HDU 4422 The Little Girl who Picks Mushrooms(数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=4422 Problem Description It's yet another festival s ...

  2. HDU 4422 The Little Girl who Picks Mushrooms(简单题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4422 题目大意:小姑娘背着5个包去山上采蘑菇,每座山上只能用一个背包采集.三个小精灵会要她3个背包,其 ...

  3. HDU 4422 The Little Girl who Picks Mushrooms

    题意:一共有5座山,已知小女孩在n座山采了n篮蘑菇,如果n小于5则在其他的山里采了任意重量的蘑菇,给出每篮蘑菇的重量,她回去的时候会遇到仨女巫要她交出三篮蘑菇的重量和恰好为1024的倍数,否则就把她的 ...

  4. ZOJ - 3657-The Little Girl who Picks Mushrooms

    /*ZOJ Problem Set - 3657 The Little Girl who Picks Mushrooms Time Limit: 2 Seconds Memory Limit: 327 ...

  5. hdu4422The Little Girl who Picks Mushrooms

    4422 小于等于3 的时候就是1024 4的时候 讨论 5的时候讨论 注意重量为0的情况 #include <iostream> #include<cstdio> #incl ...

  6. 状态压缩 UVALive 6068 The Little Girl who Picks Mushrooms (12长春C)

    题目传送门 题意:采蘑菇.现在采了n座山,共5座山,最后要求有三个篮子的蘑菇量是1024的整数倍,丢掉后一直减1024直到不超过1024 分析:n <= 3时直接1024,否则状压枚举哪三个篮子 ...

  7. hdu 4422

    #include<stdio.h> #include<string.h> #define inf  0x7fffffff int main() {     int i,j,k, ...

  8. HDU 5831 Rikka with Parenthesis II (栈+模拟)

    Rikka with Parenthesis II 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5831 Description As we kno ...

  9. 2017"百度之星"程序设计大赛 - 复赛1001&&HDU 6144 Arithmetic of Bomb【java大模拟】

    Arithmetic of Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

随机推荐

  1. IE自动化 二(判断IP所在地)

    该脚本用来访问一个url,并取出相应结果(该脚本用来通过淘宝API实现判断一个IP所在地) #定义要访问的URL $url="http://ip.taobao.com/service/get ...

  2. 如何自学Java

    转自:http://www.360doc.com/content/12/0624/19/5856897_220191533.shtml   JAVA自学之路 JAVA自学之路 一:学会选择 为了就业, ...

  3. 【转】深入浅出异步I/O模型

    转自:http://pengpeng.iteye.com/blog/868643 从上篇文章的介绍我们知道linux内核根据TCP/IP网络模型,给我们隐藏了传输层以下的网络传输细节,我们的网络应用程 ...

  4. Java学习笔记之深入理解引用

    引言:Java中数据传递的方式,除了基本数据类型是按照值传递,其它类型全部是按照引用传递,这和C++有很大区别,但是很多网上文章都解释的不清楚,甚至是错误的,在查阅资料之后,下面整理出一个比较容易理解 ...

  5. web自己主动保存表单

    note:当中部分源代码来源网络 所用的框架:jquery 实现的功能: 1.自己主动保存表单 2.页面刷新的时候把自己主动保存的值赋值给表单元素 思路: 1.表单值改变的时候自己主动触发函数.保存表 ...

  6. 【好文翻译】一步一步教你使用Spire.Doc转换Word文档格式

    背景: 年11月,微软宣布作为ECMA国际主要合作伙伴,将其开发的基于XML的文件格式标准化,称之为"Office Open XML" .Open XML的引进使office文档结 ...

  7. C#利用lambda在函数中创建内部函数

    有使用过JS的朋友,相信都知道function.JS中的function是可以在里面在定义一个作为内部使用的.有时为了控制作用域,或者这种小函数只在这个函数体内会使用,所以就不希望在外部在作额外的定义 ...

  8. SQL Server数据库大型应用解决方案总结

    随着互联网应用的广泛普及,海量数据的存储和访问成为了系统设计的瓶颈问题.对于一个大型的互联网应用,每天百万级甚至上亿的PV无疑对数据库造成了相当高的负载.对于系统的稳定性和扩展性造成了极大的问题. 一 ...

  9. 仿Android网易新闻客户端,并增加水平图片滑动,改进阅读体验

    仿网易新闻Android端APP 主要功能展示和代码实现 差不多花了一周的时间,目前实现的了新闻下的包括头条.体育.娱乐的一系列的新闻展示,以及点击后进入的新闻详情展示. 目前效果 目前效果请访问该网 ...

  10. Android-----使用Button特效 selector+shape

    当然除了使用drawable这样的图片外今天谈下自定义图形shape的方法,对于Button控件Android上支持以下几种属性shape.gradient.stroke.corners等. 我们就以 ...