Codeforce 1255 Round #601 (Div. 2) A. Changing Volume (贪心)
Bob watches TV every day. He always sets the volume of his TV to bb. However, today he is angry to find out someone has changed the volume to aa. Of course, Bob has a remote control that can change the volume.
There are six buttons (−5,−2,−1,+1,+2,+5−5,−2,−1,+1,+2,+5) on the control, which in one press can either increase or decrease the current volume by 11, 22, or 55. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than 00.
As Bob is so angry, he wants to change the volume to bb using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given aa and bb, finds the minimum number of presses to change the TV volume from aa to bb.
Input
Each test contains multiple test cases. The first line contains the number of test cases TT (1≤T≤10001≤T≤1000). Then the descriptions of the test cases follow.
Each test case consists of one line containing two integers aa and bb (0≤a,b≤1090≤a,b≤109) — the current volume and Bob's desired volume, respectively.
Output
For each test case, output a single integer — the minimum number of presses to change the TV volume from aa to bb. If Bob does not need to change the volume (i.e. a=ba=b), then print 00.
Example
Input
3
4 0
5 14
3 9
Output
2
3
2
Note
In the first example, Bob can press the −2−2 button twice to reach 00. Note that Bob can not press −5−5 when the volume is 44 since it will make the volume negative.
In the second example, one of the optimal ways for Bob is to press the +5+5 twice, then press −1−1 once.
In the last example, Bob can press the +5+5 once, then press +1+1.
能选5的时候选5,不能选5的时候选2,不能选2的时候选1。
验证可行性,如果有个大于等于5的数,不选5那么至少要选两个2一个1,甚至更多,所以直接贪心,完事。
#include<bits/stdc++.h>
#define MAXM 100000000
#define MAXN 1000005
using namespace std;
int main()
{
int a,b,t;
cin>>t;
while(t--)
{
cin>>a>>b;
int ans=abs(a-b);
int c=ans%5;
int sum=(ans-c)/5;
ans=c%2;
sum+=(c-ans)/2+ans;
cout<<sum<<endl;
}
}
Codeforce 1255 Round #601 (Div. 2) A. Changing Volume (贪心)的更多相关文章
- Codeforce 1255 Round #601 (Div. 2)D. Feeding Chicken (模拟)
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he deci ...
- Codeforce 1255 Round #601 (Div. 2) C. League of Leesins (大模拟)
Bob is an avid fan of the video game "League of Leesins", and today he celebrates as the L ...
- Codeforce 1255 Round #601 (Div. 2)B. Fridge Lockers(思维)
Hanh lives in a shared apartment. There are nn people (including Hanh) living there, each has a priv ...
- Codeforces Round #601 (Div. 2) A Changing Volume
好吧,其实我拿到这个题的时候,首先想到了bfs,写完之后,开开森森的去交代码,却在第二个数据就TEL,然后优化半天,还是不行. 最终,我盯着1,2,5发呆半天,wc,然后直接贪心 #include&l ...
- 【cf比赛记录】Codeforces Round #601 (Div. 2)
Codeforces Round #601 (Div. 2) ---- 比赛传送门 周二晚因为身体不适鸽了,补题补题 A // http://codeforces.com/contest/1255/p ...
- Codeforces Round #601 (Div. 2)
传送门 A. Changing Volume 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/19 22:37:33 */ #include ...
- codeforce Codeforces Round #201 (Div. 2)
cf 上的一道好题: 首先发现能生成所有数字-N 判断奇偶 就行了,但想不出来,如何生成所有数字,解题报告 说是 所有数字的中最大的那个数/所有数字的最小公倍数,好像有道理:纪念纪念: #incl ...
- CodeForce edu round 53 Div 2. D:Berland Fair
D. Berland Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version)
Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version) N个盒子,每个盒子有a[i]块巧克力,每次操作可以将盒子中的 ...
随机推荐
- javascript 入门 之select2获取远程数据
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <meta lan ...
- html字体大小与颜色设置
代码架构:<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> //浏览器识 ...
- Redis cluster集群配置教程
这里建议大家安装4.0.9版本的 1.打开Centos虚拟机,登陆. 2.通过WinSCP把Redis集群tar包上传到虚拟机里的目录里,我的目录是 /usr/local 这里我已经上传过了并解压了, ...
- Vue-router 第5节 vue-router利用url传递参数
Vue-router 第5节 vue-router利用url传递参数 目录 Vue-router 第5节 vue-router利用url传递参数 第5节 vue-router利用url传递参数 冒号的 ...
- Ceph学习笔记(4)- OSD
前言 OSD是一个抽象的概念,对应一个本地块设备(一块盘或一个raid组) 传统NAS和SAN存储是赋予底层物理磁盘一些CPU.内存等,使其成为一个对象存储设备(OSD),可以独立进行磁盘空间分配.I ...
- std::string::assign函数
string& assign (const string& str); string& assign (const string& str, size_t subpos ...
- Python的深浅copy详解
Python的深浅copy详解 目录 Python的深浅copy详解 一.浅copy的原理 1.1 浅copy的定义 1.2 浅copy的方法 二.深copy的原理 2.1 深copy的定义 2.2 ...
- MergeSort归并排序和利用归并排序计算出数组中的逆序对
首先先上LeetCode今天的每日一题(面试题51. 数组中的逆序对): 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数. ...
- VSCode六大通用插件真香合集
目录 一.background:设置心水背景图 安利理由: 安装及设置步骤: 设置过程中使用的代码: 成果展示: 注意: 二.Material Theme(VSCode主题)+Material Ico ...
- 实体识别中,或序列标注任务中的维特比Viterbi解码
看懂这个算法,首先要了解序列标注任务 QQ522414928 可以在线交流 大体做一个解释,首先需要4个矩阵,当然这些矩阵是取完np.log后的结果, 分别是:初始strat→第一个字符状态的 ...