The Little Girl who Picks Mushrooms(HDU
来源:互联网 发布:万代淘宝独角兽 编辑:程序博客网 时间:2024/06/05 03:57
一、大概题意:
该题的单位换算:1千克 = 1024 克
小姑娘到5个山头采蘑菇,每个山头最多采2012克蘑菇。采完蘑菇回家的路上,她会碰到两拨人。
第一波人问她要小姑娘所采的任意三个山的全部蘑菇,要求这3个山的全部蘑菇必须是1千克的整数倍,否则把她的蘑菇全部拿走。
第二波人会看小姑娘的剩余蘑菇是否大于1千克,如果大于,会一直拿,直到小姑娘的蘑菇小于等于1千克。
根据所给n,可知小姑娘在wi(1<=i<=n)个山中所采的蘑菇,求她能拿回家的最多多少克蘑菇。
注意:对于第一波人,0也是1千克的整数倍。
二、大体思路
(1) n<=3,不论如何,答案都是1024克。
(2)n = 4,方案一,她从已采的4个山头选满足题意的3个山头,答案是1024。
方案二,她从已采的4个山头选2个蘑菇数量之和余模的最小的山头,记作m,然后从第五个山头采相应的1024 - m就好。答案是剩下2个山头的蘑菇数量之和余模。
(2)n = 5,她从已采的5个山头选满足题意的3个山头,答案是剩下2个山头的蘑菇数量之和余模。 或者没有满足第一波人,蘑菇全部被抢走,答案是0。
三、附代码
#include<iostream>#include<cstdio>#include<algorithm>#include<stack>#include<queue>#include<cstring>#include<string>#include<set>#include<cmath>#include<map>#include<sstream>using namespace std;#define inf 0x3f3f3f3ftypedef long long LL;const int maxn = 10;#define MOD 1024int n,moutain[maxn];int sum;int main(){ while(cin >> n) { sum = 0; memset(moutain,0,sizeof moutain); for(int i = 1; i <= n; ++i){ scanf("%d", &moutain[i]); sum += moutain[i]; } if(n <= 3){ printf("1024\n"); continue; } int maxx = 0,tt = 0; if(n == 4){ bool flag = false; for(int i = 1; i <= 4; ++i){ for(int j = i+1; j <= 4; ++j){ for(int k = j+1; k <= 4; ++k){ int x = moutain[i] + moutain[j] + moutain[k]; if(x % MOD == 0){ flag = true; break; } } if(flag) break; } if(flag) break; } if(flag){ cout << 1024 << endl; continue; } for(int i = 1; i <= 4; ++i) { for (int j = i + 1; j <= 4; ++j) { tt = moutain[i] + moutain[j]; while (tt > 1024) tt -= 1024; maxx = max(maxx, tt); } } } if(n == 5){ for(int i = 1; i <= 5; ++i){ for(int j = i+1; j <= 5; ++j){ for(int k = j+1; k <= 5; ++k){ int z = moutain[i] + moutain[j] + moutain[k] ; if(z % MOD == 0){ tt = sum - z; while(tt > 1024) tt -= 1024; maxx = max(maxx,tt); } } } } } cout << maxx << endl; } return 0;}
阅读全文
0 0
- The Little Girl who Picks Mushrooms HDU
- The Little Girl who Picks Mushrooms(HDU
- The Little Girl who Picks Mushrooms HDU
- hdu 4422 The Little Girl who Picks Mushrooms
- hdu 4422The Little Girl who Picks Mushrooms
- hdu(4422)The Little Girl who Picks Mushrooms
- hdu 4422 The Little Girl who Picks Mushrooms
- Hdu 4422 The Little Girl who Picks Mushrooms
- HDU 4422 The Little Girl who Picks Mushrooms(模拟)
- hdu 4422——The Little Girl who Picks Mushrooms
- 【瞎搞】 HDU 4422 The Little Girl who Picks Mushrooms
- HDU 4422 The Little Girl who Picks Mushrooms(数学)
- HDU 4422 The Little Girl who Picks Mushrooms【水题】
- HDU 4422 The Little Girl Who Picks Mushrooms
- hdu 4422 The Little Girl who Picks Mushrooms(水题)
- HDU 4422 The Little Girl who Picks Mushrooms(模拟)
- The Little Girl who Picks Mushrooms
- HDUOJ4422 The Little Girl who Picks Mushrooms
- 数据结构实验之链表四:有序链表的归并
- redis sentinel高可用主从切换(非集群模式)
- php中file_get_contents与curl性能比较分析
- 6.0权限
- [Leetcode] 73, 134, 53
- The Little Girl who Picks Mushrooms(HDU
- ProgressBar 深入分析
- 字符串函数模拟实现之strcpy、strncpy、strcmp、strncmp、strcat、strncat
- Jmter一些使用技巧
- 51Nod
- 用ActiveMQ进行C++与C#的通信3
- C#防SQL注入代码的三种方法
- Baidu Map 自动定位
- js -- 设置、获取、删除cookie