Holding Bin-Laden Captive!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 21379    Accepted Submission(s): 9486

Problem Description
We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But recently, it is reported that he hides in Hang Zhou of China! 
“Oh, God! How terrible! ”

Don’t be so afraid, guys. Although he hides in a cave of Hang Zhou, he dares not to go out. Laden is so bored recent years that he fling himself into some math problems, and he said that if anyone can solve his problem, he will give himself up! 
Ha-ha! Obviously, Laden is too proud of his intelligence! But, what is his problem?
“Given some Chinese Coins (硬币) (three kinds-- 1, 2, 5), and their number is num_1, num_2 and num_5 respectively, please output the minimum value that you cannot pay with given coins.”
You, super ACMer, should solve the problem easily, and don’t forget to take $25000000 from Bush!

 
Input
Input contains multiple test cases. Each test case contains 3 positive integers num_1, num_2 and num_5 (0<=num_i<=1000). A test case containing 0 0 0 terminates the input and this test case is not to be processed.
 
Output
Output the minimum positive value that one cannot pay with given coins, one line for one case.
 
Sample Input
1 1 3
0 0 0
 
Sample Output
4
 
Author
lcy
 
Recommend
We have carefully selected several similar problems for you:  1171 1398 1028 2152 2082 

题意:

给出若干枚1元2元和5元硬币,求问最小的无法组成的面值...

分析:

我们可以把它写成生成函数的形式:$f(x)=(1+x+x^{2}+……+x^{a})(1+x^{2}+x^{4}+……+x^{2b})(1+x^{5}+x^{10}+……+x^{5c})$...

对于每一个x项,它的指数代表可以组成的硬币的面值,系数代表方案数...乘起来之后的所有x项的指数就是可以组成的面值...

然后我们可以暴力$O(n^{2})$的计算多项式乘法...因为我们只需要知道指数为x的那一位系数是否为0,所以可以用bitset优化...

但是对于此题来说有一个很机智的做法:感谢@YouSiki...

http://www.cnblogs.com/yousiki/p/6422036.html

代码:

bitset暴力:

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<bitset>
//by NeighThorn
using namespace std; const int maxn=1000+5; bitset<8005> s; int a,b,c,ans; signed main(void){
while(scanf("%d%d%d",&a,&b,&c)){
if(a==0&&b==0&&c==0)
break;
s.reset();
for(int i=0;i<=a;i++)
for(int j=0;j<=b;j++)
s.set(i+j*2);
for(int i=a+b*2;i>=0;i--)
if(s[i])
for(int j=c;j>=0;j--)
s.set(i+j*5);
int ans=1;
while(s[ans]) ans++;
printf("%d\n",ans);
}
return 0;
}

  

机智做法:

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
//by NeighThorn
using namespace std; int a[3],s[3]={1,2,5}; signed main(void){
while(scanf("%d%d%d",&a[0],&a[1],&a[2])){
if(a[0]==0&&a[1]==0&&a[2]==0)
break;
int ans=1;
while(13){
int sum=0;
for(int i=0;i<3;i++)
if(s[i]<=ans)
sum+=s[i]*a[i];
if(sum<ans){
printf("%d\n",ans);
break;
}
else
ans=sum+1;
}
}
return 0;
}

  


By NeighThorn

HDOJ 1085 Holding Bin-Laden Captive!的更多相关文章

  1. HDOJ 1085 Holding Bin-Laden Captive! (母函数)

    Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  2. HDOJ/HDU 1085 Holding Bin-Laden Captive!(非母函数求解)

    Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for ...

  3. HDU 1085 Holding Bin-Laden Captive! (母函数)

    Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  4. HDU 1085 Holding Bin-Laden Captive!(母函数,或者找规律)

    Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  5. HDU 1085 Holding Bin-Laden Captive!(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1085 解题报告:有1,2,5三种面值的硬币,这三种硬币的数量分别是num_1,num_2,num_5, ...

  6. hdu 1085 Holding Bin-Laden Captive!

    Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for ...

  7. HDU 1085 Holding Bin-Laden Captive! 活捉本拉登(普通型母函数)

    题意: 有面值分别为1.2.5的硬币,分别有num_1.num_2.num_5个,问不能组成的最小面值是多少?(0<=每种硬币个数<=1000,组成的面值>0) 思路: 母函数解决. ...

  8. HDU 1085 Holding Bin-Laden Captive --生成函数第一题

    生成函数题. 题意:有币值1,2,5的硬币若干,问你最小的不能组成的币值为多少. 解法:写出生成函数: 然后求每项的系数即可. 因为三种硬币最多1000枚,1*1000+2*1000+5*1000=8 ...

  9. hdu 1085 Holding Bin-Laden Captive! (母函数)

    //给你面值为1,2,5的三种硬币固定的数目,求不能凑出的最小钱数 //G(x)=(1+x+...+x^num1)(1+x^2+...+x^2num2)(1+x^5+,,,+x^5num3), //展 ...

随机推荐

  1. HH的项链题解(离线思想+链表+树状数组)

    本人第一篇博客重磅推出!!! 希望各位朋友以后多多捧场也多给写意见(我个人喜欢把题解写得啰嗦一点,因为这样方便理解,各位巨佬勿喷) 来讲一道提高+/省选-的骚题:HH的项链(这个HH你理解成皇后呵呵哈 ...

  2. Spring+ ApplicationListener

    有时候 需要在容器初始化完成后,加载些 代码字典或不常变的信息  放入缓存之类的,这里使用spring 初始化bean,并实例化 1.创建一个ApplicationListener类 import o ...

  3. 单片机入门学习笔记5:STC下载器

    STC下载器主要集成了, 1.芯片识别,下载/编程 2.端口识别 3.串口助手 4.KEIL仿真设置 5.芯片选型 6.范例程序 (集成了定时器,串口等例程) 7.波特率计算器 8.定时器计算器 9. ...

  4. (转)iOS静态库与动态库的区别

    一.什么是库? 库是共享程序代码的方式,一般分为静态库和动态库. 静态库:链接时完整地拷贝至可执行文件中,被多次使用就有多份冗余拷贝. 动态库:链接时不复制,程序运行时由系统动态加载到内存,供程序调用 ...

  5. 【Akroma, Angel of Fury】完成svn环境搭建

    昨天的那篇博文恰恰是实验室所干的事儿 但是那是一种很投机取巧的方式完成的多project管理方式 来看看我建立环境的方法 首先,找一个比较闲的公用服务器(为什么不用自己的?有公共资源不用,你傻啊?), ...

  6. 常用的一些api

    发送手机短信 // 发送短信给安全号码 SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(phon ...

  7. mysql基础查询

    #进阶1:基础查询/*语法:select:查询列表 from 表名; 类似于:System.out.println(打印的东西); 特点:1.查询列表可以是:表中的字段.常量值.表达式.函数2.查询的 ...

  8. Linux之我有你也有-共享平台NFS服务器搭建

    Linux之我有你也有-共享平台NFS服务器搭建 最近因工作需要,所以要搭一个共享的服务器用于存储.实现你有我有大家有的共享的和谐局面.想到了NFS-Network File System.接下来我便 ...

  9. Python框架之Django学习笔记(十二)

    Django站点管理 十一转眼结束,说好的充电没能顺利开展,反而悠闲的看了电视剧以及去影院看了新上映的<心花路放>.<亲爱的>以及<黄金时代>,说好的劳逸结合现在回 ...

  10. Python 操作 PostgreSQL 数据库

    我使用的是 Python 3.7.0 PostgreSQL可以使用psycopg2模块与Python集成. sycopg2是用于Python编程语言的PostgreSQL数据库适配器. psycopg ...