HDU 1085-Holding Bin-Laden Captive!(生成功能)

HDU 1085-Holding Bin-Laden Captive!(生成功能)

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

Holding Bin-Laden Captive!

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




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! ”


HDU 1085-Holding Bin-Laden Captive!(生成功能)

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
仍旧是母函数水过。
题意:有3种面值的硬币{1,2,5} 如今给出这3种硬币的个数,求最小不能组成的面值。

暴力生成 a[]数组扫一遍第一个为0的就是最小不能组成的面值
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#define maxn 100100
#define ll long long
#define INF 0x3f3f3f3f
#define pp pair<int,int>
using namespace std;
int a[maxn],b[maxn],v[3]={1,2,5},p,n[3];
void solve()
{
	p=n[0]+n[1]*2+n[2]*5;
	memset(a,0,sizeof(a));
	a[0]=1;
	for(int i=0;i<3;i++)
	{
		memset(b,0,sizeof(b));
		for(int j=0;j<=n[i]&&j*v[i]<=p;j++)
			for(int k=0;k+j*v[i]<=p;k++)
			b[k+j*v[i]]+=a[k];
		memcpy(a,b,sizeof(b));
	}
	int ans;
	for(ans=0;ans<=p;++ans)
		if(a[ans]==0)break;
	printf("%d\n",ans);
}
int main()
{
	while(~scanf("%d%d%d",&n[0],&n[1],&n[2]))
	{
		if(!n[0]&&!n[1]&&!n[2])break;
		solve();
	}
	return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/116966.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • Java中高级工程师面试题及答案,Java面试题及答案汇总(二

    Java中高级工程师面试题及答案,Java面试题及答案汇总(二需要注意Jdk1.8中对HashMap的实现做了优化,当链表中的节点数据超过八个之后,该链表会转为红黑树来提高查询效率,从原来的O(n)到O(logn)24.说一下HashSet的实现原理?HashSet底层由HashMap实现HashSet的值存放于HashMap的key上HashMap的value统一为PRESENT25.ArrayList和LinkedList的区别是什么?最明显的区别是ArrrayList底层的数据结构是数组,支持随机访问,而Linke

  • pycharm输入不了中文_pycharm可以设置成中文吗

    pycharm输入不了中文_pycharm可以设置成中文吗ubuntu18.04中PyCharm当全拼输入2~3个汉字时,会被强行打断,然后就无法继续输入(也无法切换中英文),并且汉字下会有下划线。点击菜单“Help|EditCustomVMoptions…”添加-Drecreate.x11.input.method=true到最后一行重启编辑器…

  • Android 面试精华题目总结

    Android 面试精华题目总结下面的题目都是楼主在android交流群大家面试时遇到的,如果大家有好的题目或者好的见解欢迎分享,楼主将长期维护此帖。1、请解释下在单线程模型中Message,Handler,MessageQueue,Lopper之间的关系。2、如果有个100M大的文件,需要上传至服务器中,而服务器form表单最大只能上传2M,可以用什么方法。3、内存溢出和内存泄漏有什么区别

  • 基于Tensorflow + yolo3的安全帽识别系统[通俗易懂]

    基于Tensorflow + yolo3的安全帽识别系统[通俗易懂]最近做了一个新的项目,需要将图片或者视频中的人员是否戴安全帽识别出来,并且在网站上进行显示.首先是正常的登录注册目前登录注册有很多方式,这个比较常规,用户名密码登录,也没有写的很复杂.接下来就是主要功能页面了如上图所示,可以进行图片及视频识别图片上传,正在进行识别…

  • forkjoin原理_java forkjoinpool

    forkjoin原理_java forkjoinpool要求一个数组内有10万个30左右的数值(非零),要求计算这些值的乘积。-时间要求:2s-堆内存大小:4m实现方案通过ForkJoin实现。代码实现importcom.google.common.base.Joiner;importcom.google.common.base.Splitter;importorg.apache.commons.l…

  • throw 和 throws 的区别?

    throw 和 throws 的区别?throw和throws的区别?throw:表示方法内抛出某种异常对象 如果异常对象是非RuntimeException则需要在方法申明时加上该异常的抛出即需要加上throws语句或者在方法体内trycatch处理该异常,否则编译报错 执行到throw语句则后面的语句块不再执行throws:方法的定义上使用throws表示这个方法可能抛出某种…

    2022年10月24日

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号