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.

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);
            }
        }
    }
}
目录
相关文章
|
存储 缓存 Java
详解Zookeeper(铲屎官)在众多中间件的应用和在Spring Boot业务系统中实现分布式锁和注册中心解决方案
`ZooKeeper `是一个**开放源码的分布式协调服务**,它是集群的管理者,监视着集群中各个节点的状态根据节点提交的反馈进行下一步合理操作。最终,将简单易用的接口和性能高效、功能稳定的系统提供给用户。 分布式应用程序可以基于` Zookeeper` 实现诸如**数据发布/订阅、负载均衡、命名服务、分布式协调/通知、集群管理、Master 选举、分布式锁和分布式队列**等功能。
24475 11
详解Zookeeper(铲屎官)在众多中间件的应用和在Spring Boot业务系统中实现分布式锁和注册中心解决方案
电脑登录某些网站失败的解决方法-关闭网络代理
电脑登录某些网站失败的解决方法-关闭网络代理
1213 0
电脑登录某些网站失败的解决方法-关闭网络代理
|
存储
VirtualBox安装的Mac虚拟机,安装增强功能失败,应该是版本太新
VirtualBox安装的Mac虚拟机,安装增强功能失败,应该是版本太新
678 0
|
IDE Java 开发工具
[软考]之树与二叉树的遍历
[软考]之树与二叉树的遍历
|
监控 关系型数据库 数据库
|
4天前
|
人工智能 JSON 安全
|
4天前
|
云安全 人工智能 安全
|
4天前
|
人工智能 自然语言处理 数据挖掘
Qwen3.8-Max-Preview深度全解析:2.4万亿参数旗舰MoE模型+Token Plan限时优惠完整落地指南
2026年7月,全新旗舰级混合专家大模型Qwen3.8-Max-Preview正式开放抢先体验,作为通义千问Qwen3系列规格最高、综合推理能力顶尖的新一代模型,该模型总参数量达到2.4万亿(2.4T),是当前线上可调用的原生多模态旗舰模型,综合推理水准对标海外顶级Fable 5模型,在复杂工程开发、长文档深度分析、多步骤智能体自治、跨境多语言创作、海量数据挖掘五大高难度业务场景实现跨越式性能提升。
738 0

热门文章

最新文章