ZOJ - 3657-The Little Girl who Picks Mushrooms
/*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的更多相关文章
- HDU 4422 The Little Girl who Picks Mushrooms ( 模拟)
Problem Description It's yet another festival season in Gensokyo. Little girl Alice planned to pick ...
- 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 ...
- 状态压缩 UVALive 6068 The Little Girl who Picks Mushrooms (12长春C)
题目传送门 题意:采蘑菇.现在采了n座山,共5座山,最后要求有三个篮子的蘑菇量是1024的整数倍,丢掉后一直减1024直到不超过1024 分析:n <= 3时直接1024,否则状压枚举哪三个篮子 ...
- hdu4422The Little Girl who Picks Mushrooms
4422 小于等于3 的时候就是1024 4的时候 讨论 5的时候讨论 注意重量为0的情况 #include <iostream> #include<cstdio> #incl ...
- HDU 4422 The Little Girl who Picks Mushrooms
题意:一共有5座山,已知小女孩在n座山采了n篮蘑菇,如果n小于5则在其他的山里采了任意重量的蘑菇,给出每篮蘑菇的重量,她回去的时候会遇到仨女巫要她交出三篮蘑菇的重量和恰好为1024的倍数,否则就把她的 ...
- HDU 4422 The Little Girl who Picks Mushrooms(简单题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4422 题目大意:小姑娘背着5个包去山上采蘑菇,每座山上只能用一个背包采集.三个小精灵会要她3个背包,其 ...
- zoj 3657 策略题 easy
http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=4880 由于是要去牡丹江.是浙大出题,所以找了份浙大的题,第一道水题做的就不顺 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
随机推荐
- 原生js实现ajax的文件异步提交功能、图片预览功能.实例
采用html5使得选择图片改变时,预览框中图片随之改变.input文件选择框美化.原生js完成文件异步提交 效果图: 代码如下,可直接复制并保存为html文件打开查看效果 <html> & ...
- 《高级Web应用程序设计》课程学习(20170911)
一.课程内容 本学期课件,点击查看 二.作业相关 上交作业的方法 访问ftp://192.168.42.254:22,登录后找到自己的姓名文件夹,放入作业即可.登录账号为stu1,密码为空 作业列表, ...
- 解决点击tomcat的startup.bat一闪而过的问题
问题: 点击startup.bat一闪而过,经过网上查询,原来是没有配置JAVA_HOME,配置一下就可以了 原因: tomcat在启动时,会读取环境变量的信息,需要一个CATALINA_HOME 与 ...
- [转载]浏览器中输入url 并且按下回车之后发生了什么?
解析URL 浏览器通过 URL 能够知道下面的信息: Protocol "http" 使用HTTP协议 Resource "/" 请求的资源是主页(index) ...
- [转]Ubuntu默认root用户密码
Ubuntu默认root用户密码 在试验的过程中,安装完Ubuntu后忽然意识到没有设置root密码,不知道密码自然就无法进入根用户下. 到网上搜了一下,原来是这么回事:Ubuntu的默认root密码 ...
- MIPS 汇编指令学习
MIPS 寄存器 MIPS comes with 32 general purpose registers named $0. . . $31Registers also have symbolic ...
- oracle过滤某个字段重复记录,只获取一条记录
一,首先想到: 1,关键字distinct 2,group by 3,MAX,MIN这样的函数被称为聚集函数,和GROUP搭配起来用 但均无法实现,执行结果如下 举例: 表名:OffsiteOutre ...
- contentType 'text/xml; charset=UTF-8' conflicts问题
Resin升级到3.1.3后,有同事发现原来在Resin 3.0.xx下成功运行的部分jsp文件(输出xml格式文件)编译出错: 1234567 500 Servlet Exception XXXXX ...
- python 安装psutil包报错:
报错: Failed building wheel for psutil Google得知,需要安装python-devel 和 wheel sudo dnf install python-devel ...
- BZOJ3033: 太鼓达人(欧拉回路)
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 524 Solved: 400[Submit][Status][Discuss] Description ...