题目链接:http://acm.hdu.edu.cn/showproblem.php?

pid=4422

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

题意:

一共同拥有5座山。每座山有非常多的蘑菇,给出一个 n 表示已经採了 n 座山上的蘑菇,求最多带回去多少蘑菇。。

当採完5座山后。有三个人拿走三个袋子里的蘑菇,这三个的袋子的蘑菇数量为1024的倍数;

假设没有三个袋子的蘑菇数目满足情况。则拿走5个袋子,即不能带走不论什么蘑菇。

而且回家的路上有人偷蘑菇。一直偷。直到总蘑菇数不大于1024;

PS:

假设n小于等于3。那么一定能拿回家1024的蘑菇!

假设n大于3,则分类讨论!

代码例如以下:

#include <cstdio>
#include <cstring>
int main()
{
int a[7];
int t;
int n;
while(~scanf("%d",&n))
{
int sum = 0;
for(int i = 0; i < n; i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
if(n <= 3)
{
printf("1024\n");
continue;
}
int maxx = 0, tt = 0;
if(n == 4)
{
int flag = 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)
{
flag = 1;
}
}
}
}
if(flag)
{
printf("1024\n");
continue;
}
for(int i = 0; i < 4; i++)
{
for(int j = i+1; j < 4; j++)
{
tt= a[i]+a[j];
while(tt > 1024)
tt-=1024;
if(tt > maxx)
{
maxx = tt;
}
}
}
printf("%d\n",maxx);
continue;
}
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++)
{
int ss = a[i]+a[j]+a[k];
if(ss%1024==0)
{
tt = sum - ss;
while(tt >1024)
tt-=1024;
if(tt > maxx)
{
maxx = tt;
}
}
}
}
}
printf("%d\n",maxx);
}
}
return 0;
}

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 题目大意:小姑娘背着5个包去山上采蘑菇,每座山上只能用一个背包采集.三个小精灵会要她3个背包,其 ...

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

    Problem Description It's yet another festival season in Gensokyo. Little girl Alice planned to pick ...

  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 - 6409:没有兄弟的舞会(数学+思维)

    链接:HDU - 6409:没有兄弟的舞会 题意: 题解: 求出最大的 l[i] 的最大值 L 和 r[i] 的最大值 R,那么 h 一定在 [L, R] 中.枚举每一个最大值,那么每一个区间的对于答 ...

  9. HDU 6108 小C的倍数问题 【数学】 (2017"百度之星"程序设计大赛 - 初赛(A))

    小C的倍数问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

随机推荐

  1. String中indexof函数的用法

    int indexOf(int ch) 返回指定字符在此字符串中第一次出现处的索引. int indexOf(int ch, int fromIndex) 从指定的索引开始搜索,返回在此字符串中第一次 ...

  2. Python9-day3-作业

    ascli  字母,数字.特殊字符,1个字节.8位 unicode:16位 两个字节,升级32位,四个字节 utf-8:最少一个字节 8位,英文字母, 1,有变量name = "aleX l ...

  3. 生物信息学练习2- Biom-format

    The Biological Observation Matrix (BIOM) format http://biom-format.org/ biom-format有两种方式安装: 1. pytho ...

  4. 剑指Offer(书):链表的倒数第K个节点

    题目:输入一个链表,输出该链表中倒数第k个结点. 分析:要注意三点:链表为空:链表个数小于k:k的值<=0; public ListNode FindKthToTail(ListNode hea ...

  5. 五、docker配置镜像加速器之阿里云

    1 配置docker加速器 实在忍受不了pull的速度--------- 访问网址: https://dev.aliyun.com/search.html 点击管理中心: 根据操作稳定配置:

  6. vim第五章 命令行模式

    vim第五章命令行模式 技巧 27 结识vim的命令行模式 在命令行模式中执行的命令有被称作ex命令    在按/调出查找提示符或者<C-r>=访问表示寄存器时 命令行模式也被激活     ...

  7. pytorch保存模型等相关参数,利用torch.save(),以及读取保存之后的文件

    本文分为两部分,第一部分讲如何保存模型参数,优化器参数等等,第二部分则讲如何读取. 假设网络为model = Net(), optimizer = optim.Adam(model.parameter ...

  8. numpy array_split()

    numpy.array_split(ary, indices_or_sections, axis=0)[source] Split an array into multiple sub-arrays. ...

  9. 组合数学的卡特兰数 TOJ 3551: Game of Connections

    这个就是卡特兰数的经典问题 直接用这个公式就好了,但是这个题涉及大数的处理h(n)=h(n-1)*(4*n-2)/(n+1) 其实见过好几次大数的处理了,有一次他存的恰好不多于30位,直接分成两部分l ...

  10. SLF4J 简单日志门面 介绍和使用

    参考:http://singleant.iteye.com/blog/934593        http://liuzidong.iteye.com/blog/776072 介绍: 简单日记门面(s ...