HDOJ/HDU 1085 Holding Bin-Laden Captive!(非母函数求解)
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
题目大意:
给你1,2,5元的硬币数量,求没办法组成的最小的数。
分析:
因为还没学母函数,用了一般的知识求解。
1、当没有一元的硬币时,肯定就是1了。
2、当一元硬币和二元硬币无法组成1-4之间的所有数字时,那么不用考虑五元的硬币,这个时候最小的数字为a+2*b+1。
3、当前面2种情况都满足时,最大的数a+2*b+5*c以内的所有数字肯定都能取到,所以最小数为:a+2*b+5*c+1。
AC代码:
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int a =sc.nextInt();
int b=sc.nextInt();
int c =sc.nextInt();
if(a==0&&b==0&&c==0){
break;
}
if(a==0){
System.out.println(1);
}else if( a+2*b<4 ){
System.out.println(a+2*b+1);
}else{
System.out.println(a+b*2+5*c+1);
}
}
}
}
HDOJ/HDU 1085 Holding Bin-Laden Captive!(非母函数求解)的更多相关文章
- Big Event in HDU(HDU1171)可用背包和母函数求解
Big Event in HDU HDU1171 就是求一个简单的背包: 题意:就是给出一系列数,求把他们尽可能分成均匀的两堆 如:2 10 1 20 1 结果是:20 10.才最均匀! 三 ...
- HDU 1085 Holding Bin-Laden Captive! (母函数)
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- hdu 1085 给出数量限制的母函数问题 Holding Bin-Laden Captive!
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- HDU 1085 Holding Bin-Laden Captive!(母函数,或者找规律)
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- 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, ...
- hdu 1085 Holding Bin-Laden Captive!
Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for ...
- HDU 1085 Holding Bin-Laden Captive! 活捉本拉登(普通型母函数)
题意: 有面值分别为1.2.5的硬币,分别有num_1.num_2.num_5个,问不能组成的最小面值是多少?(0<=每种硬币个数<=1000,组成的面值>0) 思路: 母函数解决. ...
- HDU 1085 Holding Bin-Laden Captive --生成函数第一题
生成函数题. 题意:有币值1,2,5的硬币若干,问你最小的不能组成的币值为多少. 解法:写出生成函数: 然后求每项的系数即可. 因为三种硬币最多1000枚,1*1000+2*1000+5*1000=8 ...
- 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), //展 ...
随机推荐
- Poj 3061 Subsequence(二分+前缀和)
Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12333 Accepted: 5178 Descript ...
- 实例:图形绘制[OpenCV 笔记15]
DrawShapes.cxx # include "DrawShapes_utils.h" #define WINDOW_NAME1 "Painting 1" ...
- 关于C++对汉字拼音的处理(2)
对于前面获取字符串汉字全拼音的功能,大家应该有个了解了.现在我又综合广大网友流传的获取字符串汉字拼音首字母的功能进行了整理.介绍如下 这个功能写的稍微有点复杂 使用3个函数解决了获取字符串汉字首拼音串 ...
- HDU 5619 Jam's store
Jam's store Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- thinkPHP add、save无法添加、修改不起作用
案例:数据库新添加一字段,修改值不成功.解决方案:将Runtime/Data/_fields/下面的字段缓存删除,或者直接删除整个Runtime文件也是可以的分析:由于Thinkphp,采用字段缓存机 ...
- 在ecshop商品详情页显示供货商
好久没写文章了,隐约记得前几天有人问到这个问题:[如何在ecshop商品详情页面显示该商品的供货商?] 今天有时间整理下,分享给大家. 注:以下修改适用于ecshop2.7.2,其他版本未做测试. 1 ...
- 基于类和redis的监控系统开发
最近学习python运维开发,编写得一个简单的监控系统,现记录如下,仅供学习参考. 整个程序分为7个部分: 第一个部分根据监控架构设计文档架构如下: .├── m_client│ ├── conf ...
- STM32内存映射
一.概述 STM32内存映射是STM32的架构的重要组成部分,不可或缺. 二.STM32内存映射图 1.内存映射图--摘自<CM3权威指南> 2.内存映射图--摘自<STM32F10 ...
- 常见内部函数----Python
In [10]: test = [1,2,"yes"] ---append(x) 追加到链尾 In [11]: test.append(1) In [12]: test Out[1 ...
- MyEclipse配置多个WEB容器
MyEclipse支持多个同版本WEB容器同时运行 打开 然后按下图操作 咱们就得到了 下面需要配置新增加WEB容器的启动路径,在新增加的WEB容器上点击右键,选择箭头指向的菜单 打开的窗口如图,可以 ...