题意:一共有5座山,已知小女孩在n座山采了n篮蘑菇,如果n小于5则在其他的山里采了任意重量的蘑菇,给出每篮蘑菇的重量,她回去的时候会遇到仨女巫要她交出三篮蘑菇的重量和恰好为1024的倍数,否则就把她的蘑菇都拿走,然后会遇到一个魔法师,只要小女孩剩的蘑菇数大于1024她就偷走1024,直到不大于1024为止,问小女孩最多能带回去多少蘑菇。

解法:当n小于等于3的时候,只要用一半没给出的蘑菇重量和给出的凑1024倍数给女巫,用剩下的一半再凑1024的倍数让魔法师偷,就可以拿到最大值1024,当n等于4的时候讨论两种情况:1.用给出的4篮可以凑出1024的倍数给女巫,那么用没给出的和剩下的一篮再凑1024的倍数,可以拿到最大值1024。2.如果凑不出就只能用没给出的凑,所以在那4个里挑两个被偷完能剩最大的。当n等于5时,看能不能用3个凑1024倍数,能就选剩下两个的和偷完最大不能就是0。【总之就是很麻烦……

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long using namespace std; int main()
{
int n;
while(~scanf("%d", &n))
{
if(n <= 3)
{
while(n--)
{
int a;
scanf("%d", &a);
}
puts("1024");
}
else if(n == 4)
{
int a[4];
for(int i = 0; i < 4; i++)
scanf("%d", &a[i]);
int maxn = 0;
for(int i = 0; i < 4; i++)
for(int j = i + 1; j < 4; j++)
for(int k = j + 1; k < 4; k++)
if((a[i] + a[j] + a[k]) % 1024 == 0)
maxn = 1024;
if(maxn == 0)
for(int i = 0; i < 4; i++)
for(int j = i + 1; j < 4; j++)
maxn = max(maxn, (a[i] + a[j] - 1) % 1024 + 1);
printf("%d\n", maxn);
}
else
{
int a[5];
int sum = 0;
for(int i = 0; i < 5; i++)
{
scanf("%d", &a[i]);
sum += a[i];
}
int maxn = 0;
for(int i = 0; i < 5; i++)
for(int j = i + 1; j < 5; j++)
for(int k = j + 1; k < 5; k++)
{
if((a[i] + a[j] + a[k]) % 1024 == 0)
maxn = max(maxn, (sum - a[i] - a[j] - a[k] - 1) % 1024 + 1);
}
printf("%d\n", maxn);
}
}
return 0;
}

  

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(简单题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4422 题目大意:小姑娘背着5个包去山上采蘑菇,每座山上只能用一个背包采集.三个小精灵会要她3个背包,其 ...

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

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

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

  5. hdu4422The Little Girl who Picks Mushrooms

    4422 小于等于3 的时候就是1024 4的时候 讨论 5的时候讨论 注意重量为0的情况 #include <iostream> #include<cstdio> #incl ...

  6. 状态压缩 UVALive 6068 The Little Girl who Picks Mushrooms (12长春C)

    题目传送门 题意:采蘑菇.现在采了n座山,共5座山,最后要求有三个篮子的蘑菇量是1024的整数倍,丢掉后一直减1024直到不超过1024 分析:n <= 3时直接1024,否则状压枚举哪三个篮子 ...

  7. hdu 4422

    #include<stdio.h> #include<string.h> #define inf  0x7fffffff int main() {     int i,j,k, ...

  8. hdu 6406 Taotao Picks Apples (2018 Multi-University Training Contest 8 1010)(二分,前缀和)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6406 思路: 暴力,预处理三个前缀和:[1,n]桃子会被摘掉,1到当前点的最大值,1到当前点被摘掉的桃子的 ...

  9. HDU 6406 Taotao Picks Apples & FJUT3592 做完其他题后才能做的题(线段树)题解

    题意(FJUT翻译HDU): 钱陶陶家门前有一棵苹果树. 秋天来了,树上的n个苹果成熟了,淘淘会去采摘这些苹果. 到园子里摘苹果时,淘淘将这些苹果从第一个苹果扫到最后一个. 如果当前的苹果是第一个苹果 ...

随机推荐

  1. 时序列数据库武斗大会之TSDB名录 Part 2

    [编者按] 刘斌,OneAPM后端研发工程师,拥有10多年编程经验,参与过大型金融.通信以及Android手机操作系的开发,熟悉Linux及后台开发技术.曾参与翻译过<第一本Docker书> ...

  2. Browser detect

    A useful but often overrated JavaScript function is the browser detect. Sometimes you want to give s ...

  3. HDU 3397 Sequence operation (区间合并,操作比较多)

    费了我一天半的时间,到处debug,后来才发现,主要是建树的时候只在叶子节点对lazy1和lazy2进行初始化了,父节点都没初始化...晕. 具体见代码吧. #include <iostream ...

  4. POJ 2528 Mayor's posters (线段树,染色问题,离散化要注意)

    做这题建议看一下该题的discuss. #include <iostream> #include <stdio.h> #include <string.h> #in ...

  5. js模块化开发

    主要有两个:一个是sea.js,另一个是require.js

  6. ibaits与spring整合的心得

    Ibatis2.3与spring3.0整合,其要明确一下,Ibatis与Hibernate一样都是dao层链接数据库用的框架.它是一个轻量级的orm框架,比Hibernate更加灵活. sqlMapC ...

  7. Python 中的 TK编程

    可爱的 Python:Python 中的 TK编程 http://www.ibm.com/developerworks/cn/linux/sdk/python/charm-12/ python che ...

  8. java 泛型类

     Java泛型中的标记符含义:  E - Element (在集合中使用,因为集合中存放的是元素) T - Type(Java 类) K - Key(键) V - Value(值) N - Numbe ...

  9. 非常实用的PHP代码片段推荐

    当使用PHP进行开发的时候,如果你自己收 藏 了一些非常有用的方法或者代码片段,那么将会给你的开发工作带来极大的便利.今天我们将介绍10个超级好用的PHP代码片段,希望大家能够喜欢! 1.  使用te ...

  10. netty httpserver

    netty也可以作为一个小巧的http服务器使用. package com.ming.netty.http.httpserver; import java.net.InetSocketAddress; ...