首页 > 试题广场 >

幻兽交易

[编程题]幻兽交易
  • 热度指数: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
NWU头像 NWU
#include <iostream>
#include <math.h>

using namespace std;
int main()
{
int a,b;
while(cin>>a>>b)
{
int count = 0;
int start = ceil(a/0.95);//起点(向上取整)
int end = floor(a/0.90);//终点(向下取整)
while((start % 5 != 0)&&(start<=end))
++start;
for(int i = start; i <= end&&i <= b; i += 5)
++count;
cout<<count<<endl;
}
return 0;
}

发表于 2016-06-15 18:09:54 回复(0)
#include<iostream>
#include<math.h>
using namespace std;
int main(){
    int A,B,R;
    while(cin>>A&&cin>>B){
        R=0;
        int a=ceil(A/0.95),b=floor(A/0.9);
        if(a<=B){
            if(b>B){
                R=B/5-a/5;
            }else{
                R=b/5-a/5;
            }
            if(a%5==0)
                R++;
   	}
        cout<<R<<endl;
    }
    return 0;
}

发表于 2016-06-15 10:15:58 回复(2)
#include<iostream>
#include<math.h>
using namespace std;
int main(){
    long A,B; 
    while(cin>>A>>B){
        int n=0;
        long a = ceil((double)A/19),b=(B-A)<A/9?(B-A):A/9;
        int mod = (5-(A+a)%5)%5;
        if(mod<=b&&a<=b){
            n=(b-a-mod)/5+1;
			if(a+mod>b) n--;
        }
        cout<<n<<endl;     
    }
    return 0;
}

发表于 2016-08-20 13:52:25 回复(0)
看了别人的答案,感觉都是直接用5%-10%去计算开始和结尾数据了,题的本意应该是本应消费的为A,兜里有的为B,最终给的钱数=A+(5%-10%)A,并且最终钱数是5的倍数,小于等于B.
public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
		double num = sc.nextInt();
		int m = 0;
		for(int i=1;i<=num;i++){//求出小于num的所有5的倍数
			if(i%5==0){
				//a*0.05<最终钱数i-本应付的钱数a<a*0.1
				if(a*0.05<i-a && i-a<a*0.1){
					m++;//满足计数
				}
			}
		}
		System.out.println(m);
	}

发表于 2016-09-19 22:49:30 回复(0)
#include <iostream>
#include <algorithm>
using namespace std;

int totalSolution(int A, int B)
{
    long long start = ceil(A / 0.95);
    long long end = min((long long)(A / 0.9), (long long)B);
    
    if (start>end)                       //最小总费用超过最大总费用,也即需要的费用超过B
        return 0;

    return end / 5 - ceil(start/5.0) + 1;
}

int main()
{
    long long A, B;
    while (cin >> A >> B)
    {
        cout << totalSolution(A, B) << endl;
    }

    return 0;
}

发表于 2016-08-06 12:51:12 回复(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)
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[]) {
        
        Main main = new Main();
        Scanner in = new Scanner(System.in);
     
        while(in.hasNextInt()) {
			int a = in.nextInt();
            int b = in.nextInt();
        	main.getAllProgram(a,b);
        }
    }
    
    //返回所有满足规则的 最宗支付费用
    public void getAllProgram(int a,int b) {
        int count = 0;
        //给得最少小费
        int minCost = (int)Math.ceil(a / 0.95 * 0.05);
        //给得最多小费
        int maxCost = (int)Math.floor(a / 0.90 * 0.10);
        
        for(int inner = minCost; inner <= maxCost;) {
        	int sum = a + inner;
            if(sum > b) {
                break;
            }
            if(sum % 5 == 0) {
                count++;
                inner += 5;
                continue;
            }
            
            inner++;
        }
        
       System.out.println(count);
    }
}
编辑于 2016-08-13 12:11:41 回复(0)
import sys,math
def howmany(A, B):
    begin = math.ceil(A * (1 + float(1) / 19))
    end = math.floor(A * (1 + float(1) / 9))
    end = int(min(B, end))
    start = int(begin)
    temp = start % 5  if start <= end and temp != 0 :
        start = start + 5 - temp if end == start:
        count = 1  elif end<start:
        count=0  else:
        count = (end - start) // 5+1  return count def main(): while True:
        line = sys.stdin.readline().strip() if not line: break  a = line.split()
        A = int(a[0])
        B = int(a[1])
        result = howmany(A, B) print result if __name__ == '__main__':  main()


发表于 2016-08-03 20:20:38 回复(0)
#include <stdio.h>
#include <math.h>

int main()
{
	int a, b, cnt, min, max;
	while (scanf("%d%d", &a, &b) != EOF) {
		cnt = 0;
		min = ((a/19.) > 1) ? ceil(a/19.) : 1; // 最小取值为1或者a/19向上取整 
		max = ((a/9.) < b-a) ? floor(a/9.) : b-a; // 最大取值为b-a或者a/9向下取整 
		
		//printf("min = %d\nmax = %d\n", min, max);
		
		for(int i = min; i <= max; i++){
			if((a + i) % 5 == 0){
				cnt++;
				i += 4; // 在找到第一个可行数据后直接+5,提高效率 
			}
		}
		printf("%d\n", cnt);
	}
	return 0;
}

编辑于 2016-07-31 22:19:28 回复(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)
process.stdin.resume();
process.stdin.setEncoding('ascii');
 
var input = "";
var input_array = "";
 
process.stdin.on('data', function(data) {
    input += data;
});
 
process.stdin.on('end', function() {
    input_array = input.split("\n");
    var nLine = 0;
 
    while(nLine < input_array.length) {
        var line = input_array[nLine++].trim();
        if(line === '') {
            continue;
        }
        var input_arrays = line.split(' ');
        var a = +input_arrays[0];
        var b = +input_arrays[1];
        // start
        deal(a, b);
        // end
    }
});
 
function deal(a, b) {
    var low = Math.ceil(a / 0.95/ 5) * 5;
    var high = Math.floor(a / 0.9/ 5) * 5;
    var limit = b > high ? high : Math.floor(b / 5) * 5;
    var range = limit - low;
    if(range < 0) {
        console.log(0);
    } else{
        console.log(range / 5+ 1);
    }
}
发表于 2016-06-22 11:34:48 回复(0)
//提示没在规定时间运行完成,哪位大神有空帮忙看看,提醒提醒小弟一下,谢谢了
#include<iostream>
#include<math.h>
using namespace std;
int main()
    {
    int A,B,free;
    int count;
    int t;
    int a,b;
    while(cin>>A>>B)
        {count=0;
free=0;
       t=free+A;
         a=ceil(t*0.05);
         b=floor(t*0.1);
        if(A>B)
           return 0;
         if(A<0||B<0)
             return 0;
         while(t<=B)
         {if(t%5==0)
               if(a<=free&&free<=b)
             count=count+1;
            free=free+1;
        t=free+A;
          a=ceil(t*0.05);
         b=floor(t*0.1);
          if(free>b)
              break;
    }
         cout<<count<<endl;
        }
    
    return 0;
    
}
发表于 2016-06-20 20:31:38 回复(0)


import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
long A = scan.nextLong();
long B = scan.nextLong();
int count = 0;
long begin = (long)Math.ceil(A/0.95);
long end = (long)Math.floor(A/0.9)>B?B:(long)Math.floor(A/0.9);
while(begin%5!=0){
begin++;
}
for(long i = begin;i<=end;i=i+5){
count++;
}
System.out.println(count);
}
}
}

发表于 2016-06-18 10:40:23 回复(0)
    var readline = require('readline');

    rl = readline.createInterface({
            input: process.stdin,
            output: process.stdout
    });

    rl.on('line', function(data){
      var nums = data.split(' ');
      var A = parseInt(nums[0]);
      var B = parseInt(nums[1]);

      var fee = [0,0];
      fee[0]=Math.ceil(A/0.95);
      fee[1]=Math.min(Math.floor(A/0.9),B);

      if(fee[0]>B){
        console.log(0);
      }else{
        var min = Math.ceil(fee[0]/5);
        var max = Math.floor(fee[1]/5);
        console.log(max-min+1);
      }
    });


编辑于 2016-06-16 21:57:44 回复(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 min = A / 19;
            int max = A / 9;
            min += (A % 19 != 0) ? 1 : 0;
            int count = 0;
			for (int i = min; i <= max;) {
				int sum = i + A;
                if (sum > B) break;//不这样判断会超时
				if (sum % 5 == 0) {
					count ++;
					i += 5;
					continue;
				}
				i ++;
			}
			System.out.println(count);
        }
    }
}

发表于 2016-06-16 16:57:33 回复(2)
//19 164 这个数据在本地编译器能过,但在这里过不了,求大神解释啊

#include <stdio.h>
#include <math.h>
 
 
int main()
{
    int a,b;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
        int min = ceil(0.05*a/0.95);
        int max = floor(0.1*a/0.9);
        int i=min,count=0;
        while(i<=max && a+i<=b && (a+i)%5 != 0)
        {
            i++;
        }
        if(a+i<=b && i<=max)
        {
            if(a+max <=b){
                count = count+(max-i)/5+1;      
            }
            else
            {
                count = count+(b-i-a)/5+1;   
            }
        }
        printf("%d\n",count);
    }
    return 0;
}

发表于 2016-06-16 10:27:06 回复(0)
importjava.util.Scanner;
 
publicclassMain {
 
    publicstaticvoidmain(String[] args) {
        Scanner scanner = newScanner(System.in);
        while(scanner.hasNext())
        {
            doubleA = scanner.nextDouble();//本该支付的费用
            doubleB = scanner.nextDouble();//总金额
             
            intstart = (int)Math.ceil(A/0.95);
            intend = (int)Math.floor(A/0.9);
             
            intk = 0;
            while(start%5!=0&& start <=end)
            {
                start++;
            }
            for(inti=start;i<=end && i<=B;i+=5)
            {
                if(i%5==0)
                {
                    k++;
                }
            }
            System.out.println(k);
        }
    }
 
}

发表于 2016-06-15 10:01:31 回复(0)