/*ZOJ Problem Set - 3657
The Little Girl who Picks Mushrooms
Time Limit: 2 Seconds Memory Limit: 32768 KB
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 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, lives 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 get 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 belive that 1 kilograms is equal to 1024 grams. Input There are about 8192 test cases. Process 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
Note 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 kilograms 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: Giving Sunny, Lunar and Star: (208+308+508)=1024
Stolen by Marisa: ((708+1108)-1024)=792
Author: WU, Zejun
Contest: The 2012 ACM-ICPC Asia Changchun Regional Contest
题意:

解法:

*/
#include <iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int a[];
int main()
{
int sum,MAX,flag,i,n,j,k,tmp,ans;
while(~scanf("%d",&n))
{
sum=;
MAX=;
flag=false;
for(i=; i<n; i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
if(n<=)
printf("1024\n");
else if(n==)
{
for(i=; i<n; i++)
{
sum-=a[i];
if(sum%==)
{
flag=true;
printf("1024\n");
break;
}
sum+=a[i];
}
if(!flag)
{
for(i=; i<n; i++)
for(j=i+; j<n; j++)
{
if((a[i]+a[j])%!=)
tmp=(a[i]+a[j])%;
else
{
if(a[i]+a[j]==)
tmp=;
else
tmp=;
}
MAX=max(tmp,MAX);
}
printf("%d\n",MAX);
}
}
else
{
for(i=; i<n; i++)
for(j=i+; j<n; j++)
for(k=j+; k<n; k++)
{
tmp=a[i]+a[j]+a[k];
if(tmp%==)
{
ans=sum-tmp;
if(ans%!=)
ans=ans%;
else
{
if(ans!=)
ans=;
}
MAX=max(MAX,ans);
}
}
printf("%d\n",MAX);
}
}
return ;
}
 /*二进制枚举法*/
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int del(int n,int a[]){
int r[],ct=,i=;
while(n){
if(n&){
r[ct++]=i;
}
n=n>>;
i++;
}
int t=,th=;
if(ct==){
for(i=;i<;i++)
if(i==r[]||i==r[]){
if(a[i]==-) t=;
else t+=a[i];
}else{
if(a[i]==-) th=;
else th+=a[i];
}
// printf("%d %d\n",t,th);
if(th%==){
while(t>)t-=;
return t;
}
return ;
}
return ;
}
int main(){
int n;
int i,a[];
int ans;
while(scanf("%d",&n)!=EOF){
for(i=;i<n;i++)
scanf("%d",&a[i]);
a[i]=-;
if(n<=) printf("1024\n");
else{
ans=;
for(i=;i<=;i++)
ans=max(ans,del(i,a));
printf("%d\n",ans);
}
}
return ;
}

ZOJ - 3657-The Little Girl who Picks Mushrooms的更多相关文章

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

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

  2. 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 ...

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

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

  4. hdu4422The Little Girl who Picks Mushrooms

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

  5. HDU 4422 The Little Girl who Picks Mushrooms

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

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

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

  7. zoj 3657 策略题 easy

    http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=4880 由于是要去牡丹江.是浙大出题,所以找了份浙大的题,第一道水题做的就不顺 ...

  8. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  9. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

随机推荐

  1. Android res目录结构

    所有以drawable开头的文件夹都是用来放图片的 所有以values开头的文件夹都是用来放字符串的 layout 文件夹是用来放布局文件的 menu 文件夹是用来放菜单文件的.之所以有这么多 dra ...

  2. Kotlin中常量和静态方法

    常量 Java中: class StaticDemoActivity { public static final String LOAN_TYPE = "loanType"; pu ...

  3. 浅谈webpack优化

    webpack优化方案 1. 优化开发体验 1-1. 加快构建速度 ① 缩小文件搜索范围 由于 Loader 对文件的转换操作很耗时,需要让尽可能少的文件被 Loader 处理,用include和ex ...

  4. subllime的插件使用

    1.emmet快速使用的方法. html:xt 然后按下tab快速的生成一个html文档. 生成10个div----- div*10 div->ul->li->a->img 写 ...

  5. python2和python3的区别——持续更新

    1.在 cookbook 上看到的,python3支持 *运算符 来接收迭代变量,如: a, *b = [, , , ] python2是不支持的! 2.在 cookbook 上看到的,python3 ...

  6. Rails 5 Test Prescriptions 第8章 Integration Testing with Capybara and Cucumber

    Capybara:  A complete reference is available atrubydoc.info. 集成测试就是把局部的程序组合起来测试. 端到端测试是一个特殊的集成测试,覆盖了 ...

  7. OSI七层与tcp/ip四层

    1)OSI七层模型 OSI中的层 功能 TCP/IP协议族 应用层 文件传输,电子邮件,文件服务,虚拟终端 TFTP,HTTP,SNMP,FTP,SMTP,DNS,Telnet 表示层 数据格式化,代 ...

  8. Leetcode 50

    //1开始我只是按照原来快速幂的思想,当n <0 时,n变成-n,发现当n取-INTMAX时会发生越界的问题,然后在改快速幂代码的时候逐渐了解到快速幂的本质,其实位运算对快速幂来说速度加快不了多 ...

  9. C++设计模式之适配器模式

    对象适配器有以下特点: 有的时候,你会发现,不是很容易去构造一个Adaptee类型的对象: 当Adaptee中添加新的抽象方法时,Adapter类不需要做任何调整,也能正确的进行动作: 可以使用多肽的 ...

  10. 免费一年MAP2014+6个月免费MIS2014

    活动页面:http://promos.mcafee.com/en-us/Affiliates/400/Lp/np2815_mavp.aspx?rfhs=1&LPName=np2815_mavp ...