题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4422

题目大意:小姑娘背着5个包去山上采蘑菇,每座山上只能用一个背包采集。三个小精灵会要她3个背包,其里面蘑菇的数量必须是1024的倍数,否则5个背包都会被拿走。然后魔术师会从她剩下的背包里取走蘑菇,每次取1024克,直到蘑菇不超过1024克为止。求小姑娘最多能得到多少蘑菇。

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

代码如下:

 # include<stdio.h>
# include<algorithm>
# include<iostream>
using namespace std; int n,a[],sum,ans; int calc(int x)
{
while(x > )
x -= ;
return x;
} void solve()
{
for(int i=; i<n; i++)
for(int j=i+; j<n; j++)
if(n== || (sum-a[i]-a[j])%==)
ans = max(ans,calc(a[i]+a[j]));
} int main()
{
while(scanf("%d",&n)!=EOF)
{
sum = ,ans = ;
for(int i=; i<n; i++)
{
scanf("%d",&a[i]);
sum += a[i];
}
if(n<=)
ans = ;
else if(n==)
for(int i=; i<; i++)
if((sum-a[i])%==)
ans = ;
if(ans!=)
solve();
printf("%d\n",ans);
}
return ;
}

HDU 4422 The Little Girl who Picks Mushrooms(简单题)的更多相关文章

  1. 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 ...

  2. HDU 4422 The Little Girl who Picks Mushrooms ( 模拟)

    Problem Description It's yet another festival season in Gensokyo. Little girl Alice planned to pick ...

  3. HDU 4422 The Little Girl who Picks Mushrooms

    题意:一共有5座山,已知小女孩在n座山采了n篮蘑菇,如果n小于5则在其他的山里采了任意重量的蘑菇,给出每篮蘑菇的重量,她回去的时候会遇到仨女巫要她交出三篮蘑菇的重量和恰好为1024的倍数,否则就把她的 ...

  4. HDU 1316 How Many Fibs?(java,简单题,大数)

    题目 /** * compareTo:根据该数值是小于.等于.或大于 val 返回 -1.0 或 1: public int compareTo(BigInteger val) 将此 BigInteg ...

  5. HDU - 2199 Can you solve this equation? 二分 简单题

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  6. HDU - 5999 The Third Cup is Free 贪心 简单题

    The Third Cup is Free Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  7. 2015多校联合训练赛hdu 5301 Buildings 2015 Multi-University Training Contest 2 简单题

    Buildings Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tota ...

  8. 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 ...

  9. hdu 5288||2015多校联合第一场1001题

    pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...

随机推荐

  1. android视频播放心得体会

    android视频播放主要是两种方式1.系统封装好的videoplayer,有前进.后退.暂停/播放.拉动最基本的功能,够一般使用,操作办法也很简单,如果需要自定义程度高就需要用到第二种方法:Surf ...

  2. UIView中触摸事件touchBegin

    UIView触摸事件touchBegin 等一系列方法 1)手指按下 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; ...

  3. Fragment的使用简单介绍【Android】

    Fragment在实际项目开发中使用的越来越多,如今简介一下 布局文件: <LinearLayout xmlns:android="http://schemas.android.com ...

  4. Tomcat部署web应用的三种方式

    原文:http://my.oschina.net/sunchp/blog/90235 一:相关概念 CATALINA_HOME:tomcat安装目录 CATALINA_BASE:tomcat工作目录 ...

  5. Android中由IP地址查询经纬度坐标的实例

    大家都知道,根据IP地址就可以知道它所在的具体位置,在Android中同样可以由IP地址得到它的位置,即具体的地理经纬度坐标. 本文就直接以代码的方式演示如何根据IP地址查询地理经纬度坐标位置,下面的 ...

  6. 【甘道夫】HBase基本数据操作的详细说明【完整版,精绝】

    介绍 之前具体写了一篇HBase过滤器的文章.今天把基础的表和数据相关操作补上. 本文档參考最新(截止2014年7月16日)的官方Ref Guide.Developer API编写. 全部代码均基于& ...

  7. sql server char nchar nvarchar varchar之間的區別

    char存储固定长度的字符串,最大长度为8000个字节. varchar存储可变长度的字符串.最大长度为8000个字节. nchar存储固定长度的Unicode字符串,最大长度为4000个字符. nv ...

  8. 《Linux内核修炼之道》 之 高效学习Linux内核

    http://blog.csdn.net/fudan_abc/article/details/5738436

  9. careercup-C和C++ 13.6

    13.6 基类的析构函数为何要声明为virtual? 解答: 用对象指针来调用一个函数,有以下两种情况: 如果是虚函数,会调用派生类中的版本. 如果是非虚函数,会调用指针所指类型的实现版本. 析构函数 ...

  10. Jordan Lecture Note-6: The Solutions of Nonlinear Equation.

    The Solutions of Nonlinear Equation 本文主要介绍几种用于解非线性方程$f(x)=0$的一些方法. (1) Bisection Method. 算法: step 1: ...