ZOJ 3657 The Little Girl who Picks Mushrooms(12年长春区域赛-C题-枚举)
来源:互联网 发布:linux 中断ping 编辑:程序博客网 时间:2024/05/22 11:35
题目链接:Click here~~
题意:
一共有5座山,有人拿5个篮子去采蘑菇,现在他已经采了几座山上的蘑菇,之后几座山的蘑菇数量你可以自己确定。但是他要交出3个篮子,且它们的和必须是1024的倍数。否则,剩余两个篮子也要交出。之后,如果剩余数量大于1024要减去1024直到不大于。问最后剩余的最大值。
解题思路:
水题,WA了5次,我还以为是题意理解错了。。原来有坑。。交3个篮子的时候,它们的和可以是0。。
首先,看是否能满足第一个条件,其实,只有5个篮子数量已经全部确定的时候,才有可能不满足。
如果在满足的前提下,还能够保证剩余的篮子中有一个是可以自己确定蘑菇数量的,则最后一定能剩到1024(最大值)。否则,解也已经确定。
然后,更新最大解即可。
贴个简化后的代码。
#include <stdio.h>#include <algorithm>using namespace std;int n,a[6],sum,ans;bool mult(int x){ return x%1024==0;}int calc(int x){ while(x > 1024) x -= 1024; return x;}void solve(){ for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) if(n==4 || mult(sum-a[i]-a[j])) ans = max(ans,calc(a[i]+a[j]));}int main(){ while(~scanf("%d",&n)) { sum = 0,ans = 0; for(int i=0;i<n;i++) { scanf("%d",&a[i]); sum += a[i]; } if(n<=3) ans = 1024; else if(n==4) for(int i=0;i<4;i++) if(mult(sum-a[i])) ans = 1024; if(ans!=1024) solve(); printf("%d\n",ans); }return 0;}
- ZOJ 3657 The Little Girl who Picks Mushrooms(12年长春区域赛-C题-枚举)
- HDU 4422 The Little Girl who Picks Mushrooms (2012年长春赛区现场赛C题)
- ZOJ 3657 The Little Girl who Picks Mushrooms(2012长春现场赛C题)
- zoj The Little Girl who Picks Mushrooms
- ZOJ Problem Set - 3657The Little Girl who Picks Mushrooms
- ZOJ 3657 The Little Girl who Picks Mushrooms
- The Little Girl who Picks Mushrooms
- HDUOJ4422 The Little Girl who Picks Mushrooms
- The Little Girl who Picks Mushrooms
- zoj3657-The Little Girl who Picks Mushrooms
- The Little Girl who Picks Mushrooms HDU
- The Little Girl who Picks Mushrooms(HDU
- The Little Girl who Picks Mushrooms
- The Little Girl who Picks Mushrooms HDU
- 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(模拟)
- php上传文件
- c/c++-虚函数和重载
- Sybase数据库的彻底卸载
- 在页面打印时,弹出小白框,报io异常
- Linux 进程间通信 - 共享内存shmget方式(转)
- ZOJ 3657 The Little Girl who Picks Mushrooms(12年长春区域赛-C题-枚举)
- vim列模式编辑方法
- C++的犄角旮旯
- C/C++变量在内存中的分布
- poj 2892 线段树 区间合并
- 剖析程序的内存布局
- 润乾参数模板的使用
- 各个语言垃圾回收机制汇总(C++)
- 时间2