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个苹果成熟了,淘淘会去采摘这些苹果. 到园子里摘苹果时,淘淘将这些苹果从第一个苹果扫到最后一个. 如果当前的苹果是第一个苹果 ...
随机推荐
- How does database indexing work?
When data is stored on disk based storage devices, it is stored as blocks of data. These blocks are ...
- [主席树]HDOJ3874 Necklace
题意:n个数 m个询问 询问的是[l, r]区间内不同的数的和 没有修改,静态的主席树即可 与 SPOJ QUERY 一样 将重复的元素建树即可 注意范围:$N \le 50000$ 每个值不超过1 ...
- 小米2000万买域名mi.com
来源:互联网的一些事 移动互联网之下,域名对于企业的吸引力将会越来越低,因为网站的入口多元化,不再仅凭域名.小米用超2000万人民币的代价购买mi.com域名,仅仅是为了所谓的国际化吗?小米此举, ...
- lintcode :continuous subarray sum 连续子数组之和
题目 连续子数组求和 给定一个整数数组,请找出一个连续子数组,使得该子数组的和最大.输出答案时,请分别返回第一个数字和最后一个数字的值.(如果两个相同的答案,请返回其中任意一个) 样例 给定 [-3, ...
- C#实现的ReplaceFirst和ReplaceLast
原文:C#实现的ReplaceFirst和ReplaceLast ReplaceFirst: public static string ReplaceFirst(string input, strin ...
- 未能加载文件或程序集“Interop.jmail”或它的某一个依赖项
未能加载文件或程序集“Interop.jmail”或它的某一个依赖项.试图加载格式不正确的程序. 说明: 执行当前 Web 请求期间,出现未经处理的异常.请检查堆栈跟踪信息,以了解有关该错误以及代码中 ...
- windows下python脚本程序的运行
c:\python33\python.exe c:\python33\trycoding.py
- 【Linux常用工具】03. Linux性能测试工具ab
在Apache服务器的套件中,有一个叫做 ab (ApacheBench) 的工具. ApacheBench 主要是用来测试Apache服务器执行效率用的 ApacheBench 可以针对某个特定的 ...
- oracle db shutdown immediate–multi Instance
[oracle@redhat4 ~]$ sqlplus / as sysdba@orcl SQL*Plus: Release 11.2.0.1.0 Production on Tue Oct 6 21 ...
- Android开发之ProgressDialog与ProgressBar
ProgressDialog,继承AlertDialog.所以ProgressDialog就是一个在对话框中显示ProgressDialog,并显示进度的文本信息. 并且没有取消和确定按钮,只能通过b ...