HDU 4422 The Little Girl who Picks Mushrooms
题意:一共有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的更多相关文章
- 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 ( 模拟)
Problem Description It's yet another festival season in Gensokyo. Little girl Alice planned to pick ...
- 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 6406 Taotao Picks Apples (2018 Multi-University Training Contest 8 1010)(二分,前缀和)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6406 思路: 暴力,预处理三个前缀和:[1,n]桃子会被摘掉,1到当前点的最大值,1到当前点被摘掉的桃子的 ...
- HDU 6406 Taotao Picks Apples & FJUT3592 做完其他题后才能做的题(线段树)题解
题意(FJUT翻译HDU): 钱陶陶家门前有一棵苹果树. 秋天来了,树上的n个苹果成熟了,淘淘会去采摘这些苹果. 到园子里摘苹果时,淘淘将这些苹果从第一个苹果扫到最后一个. 如果当前的苹果是第一个苹果 ...
随机推荐
- Tries
trie,又称前缀树或字典樹,是一种有序树,用于保存关联数组,其中的键通常是字符串.与二叉查找树不同,键不是直接保存在节点中,而是由节点在树中的位置决定.一个节点的所有子孙都有相同的前缀,也就是这个节 ...
- Comparable & Comparator
Comparable & Comparator 都是用来实现集合中元素的比较.排序的,只是 Comparable 是在集合内部定义的方法实现的排序,Comparator 是在集合外部实现的排序 ...
- SPOJ Lexicographical Substring Search 后缀自动机
给你一个字符串,然后询问它第k小的factor,坑的地方在于spoj实在是太慢了,要加各种常数优化,字符集如果不压缩一下必t.. #pragma warning(disable:4996) #incl ...
- Android ListView点击失效
item中存在 ImageButton 等可以点击的组件,这会抢先获得ListView的焦点. 从而导致item点击失效
- 【转】Dr.com 5.20破解教程
Dr.com 5.20破解教程 方法一 1.首先下载相关工具 Process Explorer(大家可以自行百度 一般绿色汉化版就可以)右键选择以管理员权限运行process的主程序 然后运行drc ...
- Openfire 服务端在Eclipse上部署
http://blog.csdn.net/chexitianxia/article/details/9371169 结合: http://blog.csdn.net/ares1201/article/ ...
- 使用预处理PreparedStatement执行Sql语句
/** * 使用预处理的方式执行Sql * @param sql Sql语句 * @param obj 变量值数组 * @return 查询结果 * @throws SQLException */ p ...
- *[hackerrank]Consecutive Subsequences
https://www.hackerrank.com/contests/w6/challenges/consecutive-subsequences 求数组中被k整除的子段和有几个.这个要利用sum[ ...
- JavaWeb项目开发案例精粹-第3章在线考试系统-005action层
1. <?xml version="1.0" encoding="UTF-8" ?><!-- XML声明 --> <!DOCTYP ...
- 转TransactionProxyFactoryBean代理事务
<?xml version="1.0" encoding="GBK"?> <!-- 指定Spring配置文件的DTD信息 --> < ...