hdu 1085 Holding Bin-Laden Captive!(Java)

Problem Description

(好长啊,根本不想写上来,复制都嫌麻烦)
(所以,我不打算把原文全写上来了,就写句要点吧)
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.

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.

解题思路

设3种硬币的分别有a,b,c个。
首先要理解,如果中间没有断的话,那么把所有的硬币加起来后,再多一块就是我们要的答案即 (a+2*b+5*c+1)
现在要考虑的就是中间的断层了。
每两个相同硬币之间的断层需要由比它小的硬币来补齐。
对于1元硬币,没有比之更小的了(就题中),所以两个1元硬币之间是没有断层的。
对于2元硬币,之间的断层就必须由1元硬币来补齐,所以只要有1元硬币,那两个2元硬币之间是无断层的,但如果连1元硬币都没有,那么1就会出现断层,此时可以直接输出1
对于5元硬币,之间的断层就必须由2元和1元硬币来补齐,所以只要1元硬币和2元硬币的总和大于等于4就行

代码

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){
                return;
            }
            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+2*b+5*c+1);
            }
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值