/*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. xtu 1242 Yada Number 容斥原理

    Yada Number Problem Description: Every positive integer can be expressed by multiplication of prime ...

  2. python 列表元素替换以及删除

    >>> letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] >>> letters ['a', 'b', 'c', 'd', ...

  3. 详解java中CAS机制所导致的问题以及解决——内存顺序冲突

    [CAS机制] 指的是CompareAndSwap或CompareAndSet,是一个原子操作,实现此机制的原子类记录着当前值的在内存中存储的偏移地址,将内存中的真实值V与旧的预期值A做比较,如果不一 ...

  4. OKR 说明

    转载来源: http://www.jianshu.com/p/ce1141084427 一.什么是OKR? OKR的全称是“Objectives and Key Results”,翻译过来就是“目标和 ...

  5. uva10655矩阵快速幂

    a^(n+2)+b^(n+2)=(a+b)*(a^(n+1)+b^(n+1))-a*b*(a^n+b^n) 坑爹的题目关系式都推出来了居然还是wa了..... 不能只看p,q=0就退出,因为a,b不一 ...

  6. html5 自带全屏API调用方法

    function FullScreen(){ var el = $('html')[0];//要全屏的元素,如果要全页面全屏,建议使用html节点而不是body节点 var isFullscreen= ...

  7. 在嵌入式设计中使用MicroBlaze(Vivado版本)

    原文Xilinx官方文档<ug898-vivado-embedded-design>第三章 一.MicroBlaze处理器设计介绍(略) 二.创建带有MicroBlaze处理器的IP设计 ...

  8. Webroot SecureAnywhere AntiVirus 2014 – 免费6个月

    Webroot SecureAnywhere 是由webroot推出的一款云安全软件,除了能够清除病毒外,特点是体积小.强力查杀木马.间谍软件.Rootkit 等等,为你的个人私隐信息提供全面的保护. ...

  9. 用于调试的printf函数和自定义log函数

    1. 用宏定义调试用的DPRINT #define DEBUG_ENABLE #ifdef DEBUG_ENABLE #define DPRINT(fmt, args...) fprintf(stde ...

  10. 2018.11.23 Cypress BLE module test

    CYx63BPA BLE module IQC test guide Test Jig setting:1.  Connect  USB1 and USB2 with computer serial ...