首页 > 试题广场 >

幻兽交易

[编程题]幻兽交易
  • 热度指数:2626 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
在最近几场魔兽争霸赛中,赫柏对自己的表现都不满意。
为了尽快提升战力,赫柏来到了雷鸣交易行并找到了幻兽师格丽,打算让格丽为自己的七阶幻兽升星。
经过漫长的等待以后,幻兽顺利升到了满星,赫柏很满意,打算给格丽一些小费。
赫柏给小费是有原则的:
1.最终给格丽的钱必须是5的倍数;
2.小费必须占最终支付费用的5%~10%之间(包含边界)。
升星总共耗费A魔卡,赫柏身上带了B魔卡,赫柏想知道他有多少种支付方案可供选择。
注:魔卡是一种货币单位,最终支付费用=本该支付的+小费

输入描述:
多组测试数据,请处理到文件结束。
对于每组测试数据:
包含两个整数A和B。
保证:
1<=A,B<=2,000,000,000,A<=B。


输出描述:
输出一个整数,代表方案数。
示例1

输入

4 100
23 100

输出

0
1
import java.util.*;

/**
 * Created by Wen on 2016/6/22.
 */
public class Main {

    private static int count = 0;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
           count = 0;
            int A = scanner.nextInt();
            int B = scanner.nextInt();
            int a = (int) (Math.ceil(A / 0.95));
            int b = (int) (Math.floor(A / 0.90));
            for (int i = 1; i <= 5; i++) {
                if (a % 5 == 0)
                    break;
                a++;
            }
            while (a <= b && a <= B) {
                count++;
                a += 5;
            }
            System.out.println(count);

        }
    }
}
发表于 2016-09-04 09:41:45 回复(0)
import java.util.Scanner;
public class Main{
    
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int A = in.nextInt();
            int B = in.nextInt();
            
            int star = (int)Math.ceil(A/0.95);
            int end  = (int)Math.floor(A/0.9);
            
            int count = 0;
            if(star <= B){
                if(B < end){
                    count = B/5 - star/5;
                }else{
                    count = end/5 - star/5;
                }
                
                if(star%5 ==0) count++;
            }
            
            System.out.println(count);
        }
    }
}
发表于 2016-07-19 20:09:47 回复(0)
import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedInputStream(System.in));
		while (in.hasNext()) {
			int A = in.nextInt();
			int B = in.nextInt();
			
			/*
			 *   总费用的范围为   A / 0.95 <= f <= A / 0.9
			 *   由于魔卡为整数,所以总费用范围为min <=f <= max  f为整数 
			 */
			
			int min = (int)Math.ceil(A / 0.95);
			int max = (int)Math.floor(A / 0.9);
			int ans = 0;
			if (min <= B) {
				if (max > B) {
					ans = B / 5 - min / 5;
				} else {
					ans = max / 5 - min / 5;
				}
				if (min % 5 == 0) {
					ans++;
				}
			}
			System.out.println(ans);
		}
		in.close();
	}
} 


编辑于 2016-07-06 19:18:58 回复(0)