/*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. PHP--------微商城实现微信授权登录

    前段时间做完微商城了,来把微信商城学到的一些东西分享一下,希望对各位有所帮助. PHP做后台,先来说微信商城的授权登录吧!这个几乎都有,这个功能代码其实不多,主要是看懂文档需求. 前提:要有公众号,和 ...

  2. hdu4686矩阵快速幂

    花了一个多小时终于ac了,有时候真的是需要冷静一下重新打一遍才行. 这题就是 |aod(n)|   =    |1        ax*bx       ax*by      ay*bx       ...

  3. 【MVC】MusicStore相关资料

    引言 当你对MVC的项目结构有一定了解时,那就可以开始学习一个世界级的MVC入门demo--MusicStore.学习的绝招就是把它抄一遍. 相关资料 MVC Music Store  Codeple ...

  4. hdu 6158 The Designer( 反演圆)

    The Designer Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  5. Vue.js学习笔记:在元素 和 template 中使用 v-if 指令

    f 指令 语法比较简单,直接上代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " ...

  6. 将app现有的icon转化成圆角icon

      选择圆角工具,设置半径120px   设置固定大小,然后在图片左上角开始拖动,勾勒出圆角,建立选取,自由变换,copy 选取,新建图层,删除背景,另存为,齐活   注:索引图片如何解锁: http ...

  7. Web 端屏幕适配方案

    基础知识 像素相关 1.像素 :像素是屏幕显示最小的单位. 2.设备像素 :设备像素又称物理像素(physical pixel),设备能控制显示的最小单位,我们可以把这些像素看作成显示器上一个个的点. ...

  8. 作业要求20181023-4 Alpha阶段第2周/共2周 Scrum立会报告+燃尽图 03

    作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2284] 版本控制:https://git.coding.net/liuyy08 ...

  9. iOS 关于时间天数星期月份的总结

    #import <Foundation/Foundation.h> @interface NSDate (SLExtend) // 判断是否是本周更早 - (BOOL)isThisWeek ...

  10. js:关闭当前页面

    var userAgent = navigator.userAgent; if (userAgent.indexOf("Firefox") != -1 || userAgent.i ...