The Little Girl who Picks Mushrooms HDU
来源:互联网 发布:如何学好高中政治知乎 编辑:程序博客网 时间:2024/05/21 19:07
题目描述:5个包,已经有n个包里装了东西,还要继续往剩下的包里装东西(想装多少装多少)。返程要经过两个过程,一是要交出3个东西数量之和恰好为1024整数倍的包;二是剩下两个包的东西每次都会被偷1024,直到两个包东西之和不大于1024(最大为1024)。
思路:当有2、3、4、5个包还没有装东西时输出结果一定为1024,因为至少可以用一个包凑出1024的整数倍交出去,也总有办法凑出最后两个包数量为1024。暴力即可,队友做时神卡题找不到错误点,反正就5个包,我就建议他直接暴力,if else判断过了。下面贴的是我赛后写的暴力代码。
提示:稍微需要注意一点的可能就是0也算是整数个1024,故5 0 0 0 1 3输出的4而不是0。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<cstdlib>#include<sstream>#include<deque>#include<stack>#include<set>#include<map>using namespace std;typedef long long ll;typedef unsigned long long ull;const double eps = 1e-6;const int maxn = 30;const int maxt = 1e6 + 10;const int mod = 10000007;const int dx[] = {1, -1, 0, 0, -1, -1, 1, 1};const int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};const int Dis[] = {-1, 1, -5, 5};const double inf = 0x3f3f3f3f;int n;int num[10];int main(){ while(~scanf("%d", &n)){ memset(num, 0, sizeof num); for(int i = 0; i < n; ++i){ scanf("%d", &num[i]); } if(n == 0 || n == 1 || n == 2 || n == 3){ printf("1024\n"); continue; } else if(n == 4){ bool ok = false; for(int i = 0; i < n; ++i){ for(int j = i + 1; j < n; ++j){ for(int k = j + 1; k < n; ++k){ if((num[i] + num[j] + num[k]) % 1024 == 0){ ok = true; break; } } if(ok) break; } if(ok) break; } if(ok){ printf("1024\n"); continue; } int ans = 0, tmp = 0; for(int i = 0; i < n; ++i){ for(int j = i + 1; j < n; ++j){ tmp = num[i] + num[j]; while(tmp > 1024) tmp -= 1024; ans = tmp > ans ? tmp : ans; } } printf("%d\n", ans); } else if(n == 5){ bool ok = false; int ans = 0, tmp; for(int i = 0; i < n; ++i){ for(int j = i + 1; j < n; ++j){ for(int k = j + 1; k < n; ++k){ if((num[i] + num[j] + num[k]) % 1024 == 0){ ok = true; tmp = 0; for(int x = 0; x < 5; ++x){ if(x == i || x == j || x == k) continue; tmp += num[x]; } while(tmp > 1024) tmp -= 1024; ans = tmp > ans ? tmp : ans; } } } } if(ok) printf("%d\n", ans); else printf("0\n"); } } 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
- 【bzoj2430】 [Poi2003]Chocolate
- web.xml文件详解
- 批量操作资源或控件
- Spring 4.0 学习日记(6) ---静态代理
- server.xml文件详解
- The Little Girl who Picks Mushrooms HDU
- 十分钟掌握pandas(pandas官方文档翻译)
- linux 开发调试辅助工具
- 基于Random类和ArrayList类实现斗地主发牌功能
- spring学习笔记3--AOP
- javascript中new的用法
- 【bzoj3728】 PA2014Final Zarowki
- ztree + openlayer 控制图层
- HDFS基本特性以及工作机制