zoukankan      html  css  js  c++  java
  • A.Changing Volume

    题目:改变音量##

    题意:给定两个数a和b,有6个操作(-5, -2, -1, +1, +2, +5),求a变到b的最小操作次数
    操作的过程中不能变到小于0,即音量不能调到小于0

    分析:
    (贪心),我们可以不断使用+5,直到a和b的差值小于5,然后再使用-2,-1,+1,+2这些操作
    因为如果a和b的差值大于5,显然使用+2,+2,+1的三次操作可以通过+5一次操作代替

    #include <cstdio>
    #include <algorithm>
    
    using namespace std;
    int t;
    int main()
    {
    	scanf("%d", &t);
    
    	while (t--)
    	{
    		int a, b;
    		scanf("%d%d", &a, &b);
    		if (a > b)
    			swap(a, b);
    
    		int ans = 0;
    		ans = ans + (b - a) / 5;
    		a = a + (b - a) / 5 * 5;
    		ans = ans + (b - a) / 2;
    		a = a + (b - a) / 2 * 2;
    		ans = ans + (b - a);
    		printf("%d
    ", ans);
    	}
    
    
    	return 0;
    }
    
  • 相关阅读:
    2020-03-1811:29:37springboot与任务
    2020-03-17 20:18:50springboot整合rabbitmq
    2020.03.17 springboot缓存相关
    前端JS面试
    npm 常用指令
    ES8新特性
    ES7新特性
    ES6新特性
    SpringBoot
    SpringBoot
  • 原文地址:https://www.cnblogs.com/pixel-Teee/p/11962592.html
Copyright © 2011-2022 走看看