HDU 4422 The Little Girl who Picks Mushrooms(简单题)

题目链接: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

代码如下:

 1 # include<stdio.h>
 2 # include<algorithm>
 3 # include<iostream>
 4 using namespace std;
 5 
 6 int n,a[6],sum,ans;
 7 
 8 int calc(int x)
 9 {
10     while(x > 1024)
11         x -= 1024;
12     return x;
13 }
14 
15 void solve()
16 {
17     for(int i=0; i<n; i++)
18         for(int j=i+1; j<n; j++)
19             if(n==4  || (sum-a[i]-a[j])%1024==0)
20                 ans = max(ans,calc(a[i]+a[j]));
21 }
22 
23 int main()
24 {
25     while(scanf("%d",&n)!=EOF)
26     {
27         sum = 0,ans = 0;
28         for(int i=0; i<n; i++)
29         {
30             scanf("%d",&a[i]);
31             sum += a[i];
32         }
33         if(n<=3)
34             ans = 1024;
35         else if(n==4)
36             for(int i=0; i<4; i++)
37                 if((sum-a[i])%1024==0)
38                     ans = 1024;
39         if(ans!=1024)
40             solve();
41         printf("%d\n",ans);
42     }
43     return 0;
44 }

 

转载于:https://www.cnblogs.com/acm-bingzi/p/3355336.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值