HDU 4422 The Little Girl who Picks Mushrooms ( 模拟)
Alice lives in the forest of magic. At the entry of the forest of magic, live 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 gets 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 believe that 1 kilogram is equal to 1024 grams.
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.
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 kilogram 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:
1.Giving Sunny, Lunar and Star: (208+308+508)=1024
2.Stolen by Marisa: ((708+1108)-1024)=792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include<cmath>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <stack>
#include <cctype>
using namespace std;
typedef unsigned long long ull;
#define INF 0xfffffff int main()
{
int k,m,q,p;
int T; int a[],n; while(cin>>T)
{
for(int i=;i<T;++i)
{
cin>>a[i];
}
if(T<)
{
cout<<<<endl;
}else if(T==)
{
int ans=;
m=;
q=;
for(int i=;i<T;++i)
{
for(int j=i+;j<T;++j)
{
for(int k=j+;k<T;++k)
{
if((a[i]+a[j]+a[k])%==)
{
m=;
}
}
}
}
if(m)
{
cout<<<<endl;
continue;
} k=;
for(int i=;i<T;++i)
{
for(int j=i+;j<T;++j)
{
p=a[i]+a[j];
while(p>)
{
p-=;
}
k=max(k,p);
}
}
cout<<k<<endl;
}else if(T==)
{
int ans=;
m=;
for(int i=;i<;++i)
{
for(int j=i+;j<;++j)
{
for(int k=j+;k<;++k)
{
if((a[i]+a[j]+a[k])%==)
{
m=;
q=;
for(p=;p<;++p)
{
if(p!=i&&p!=j&&p!=k)
{
q+=a[p];
}
} while(q>)
{
q-=;
}
ans=max(ans,q);
} } }
}
if(m)
{
cout<<ans<<endl;
}else
{
cout<<<<endl;
}
} }
return ;
}
HDU 4422 The Little Girl who Picks Mushrooms ( 模拟)的更多相关文章
- 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 ...
- HDU 4422 The Little Girl who Picks Mushrooms(简单题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4422 题目大意:小姑娘背着5个包去山上采蘑菇,每座山上只能用一个背包采集.三个小精灵会要她3个背包,其 ...
- HDU 4422 The Little Girl who Picks Mushrooms
题意:一共有5座山,已知小女孩在n座山采了n篮蘑菇,如果n小于5则在其他的山里采了任意重量的蘑菇,给出每篮蘑菇的重量,她回去的时候会遇到仨女巫要她交出三篮蘑菇的重量和恰好为1024的倍数,否则就把她的 ...
- ZOJ - 3657-The Little Girl who Picks Mushrooms
/*ZOJ Problem Set - 3657 The Little Girl who Picks Mushrooms Time Limit: 2 Seconds Memory Limit: 327 ...
- hdu4422The Little Girl who Picks Mushrooms
4422 小于等于3 的时候就是1024 4的时候 讨论 5的时候讨论 注意重量为0的情况 #include <iostream> #include<cstdio> #incl ...
- 状态压缩 UVALive 6068 The Little Girl who Picks Mushrooms (12长春C)
题目传送门 题意:采蘑菇.现在采了n座山,共5座山,最后要求有三个篮子的蘑菇量是1024的整数倍,丢掉后一直减1024直到不超过1024 分析:n <= 3时直接1024,否则状压枚举哪三个篮子 ...
- hdu 4422
#include<stdio.h> #include<string.h> #define inf 0x7fffffff int main() { int i,j,k, ...
- HDU 5831 Rikka with Parenthesis II (栈+模拟)
Rikka with Parenthesis II 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5831 Description As we kno ...
- 2017"百度之星"程序设计大赛 - 复赛1001&&HDU 6144 Arithmetic of Bomb【java大模拟】
Arithmetic of Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
随机推荐
- mysql中自己定义函数编程
语法: 新建: Create function function_name(參数列表)returns返回值类型 函数体 函数名,应该合法的标识符,而且不应该与已有的keyword冲突. 一个函数应该属 ...
- 主函数 main WinMain _tmain _tWinMain 的区别
main是C/C++的标准入口函数名 WinMain是windows API窗体程序的入口函数.(int WINAPI WinMain()) 中 WINAPI是__stdcall宏,在windef.h ...
- Java图片处理(二)图片加水印
图片加水印,是通过图片重叠绘制实现的.实现代码如下: public static void press(String pressImg, String pressText, String target ...
- -force_load使用办法
项目中用到Three20框架,同时也使用了讯飞语音的framework,编译时出现类似如下冲突提示信息: ld: duplicate symbol _OBJC_CLASS_$_AdLinks in / ...
- 关于测试Windows电脑端口的命令 —— telnet用法
telnet服务在win7默认是打开的,如果没有打开要在电脑中打开. 命令格式:telnet ip port 例如:telnet 127.0.0.1 80 或者 telnet www.XXX.com ...
- Struts2+hibernate3+Spring2的整合方法
浅谈Struts+hibernate+Spring的整合方法 摘要:本文将介绍Struts,Spring与hibernate的集成.希望大家能从中受用. 1.在工程中导入spring支持,导入的Jar ...
- C#操作串口总结
Technorati 标签: C#,SerialPort,ReadTo,ReadTimeout 最近几天一直在调一个要长时间连续不断的操作串口,并且是多线程运行,不允许中断的服务.后来服 ...
- C语言中将数字转换为字符串的方法
C语言提供了几个标准库函数,可以将任意类型(整型.长整型.浮点型等)的数字转换为字符串.以下是用itoa()函数将整数转换为字符串的一个例子: # include <stdio. h># ...
- C. Om Nom and Candies 巧妙优化枚举,将复杂度控制在10e6
C. Om Nom and Candies 无线超大背包问题 #include <iostream> #include <cstdio> #include <cstrin ...
- Mosaic HDU 4819 二维线段树入门题
Mosaic Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total S ...