/*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. adb connect 192.168.1.10 failed to connect to 192.168.1.10:5555

    adb connect 192.168.1.10 输出 failed to connect to 关闭安卓端Wi-Fi,重新打开连接即可

  2. 识别User Agent屏蔽一些Web爬虫防采集

    识别User Agent屏蔽一些Web爬虫防采集 from:https://jamesqi.com/%E5%8D%9A%E5%AE%A2/%E8%AF%86%E5%88%ABUser_Agent%E5 ...

  3. 在Spring Boot中使用 @ConfigurationProperties 注解 (二十六)

    @ConfigurationProperties主要作用:就是绑定application.properties中的属性 java代码 @Configuration public class DataS ...

  4. 021PHP基础知识——代码重用

    <?php /** * 代码重用 * include() require() 载入文件 * include() 如果载入的文件不存在,提示警告错误. * require() 如果载入的文件不存在 ...

  5. HDU 2612 Find a way bfs 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=2612 bfs两次就可将两个人到达所有kfc的时间求出,取两人时间之和最短的即可,这个有点不符合实情,题目应该出两 ...

  6. redis.conf配置文件参数说明

    参数说明 redis.conf 配置项说明如下: 1. Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程     daemonize no 2. 当Redis以守护 ...

  7. ROS会议 ROSCon 2017

    ----ROSCon2012-2017----来源链接:https://roscon.ros.org           近三年ROSCon(2015-2017)都会将会议视频录像和文档公开~以下为机 ...

  8. Ethereum部署私有合约常见问题汇总

    常见问题 问题1 问题描述: callback contain no result Error: authentication needed: password or unlock 这里的问题是当前所 ...

  9. Monkey测试练习

    1.下载Android SDK 2.打开SDK Manager.exe自动下载 3.配置环境变量 将platform-tools的路径(如: C:\001myWorkspace\eclipse(MAV ...

  10. XMU 1246

    http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1246 求区间内素数个数,经典问题,区间长度10^6,数的取值最多能到10^12(此题范围稍小) 用 ...