Codeforces Round #601 (Div. 2)
Codeforces Round #601 (Div. 2) A. Changing Volume 题意:有T组数据,每组数据给两个数 a 和 b ,每次可以对 a 进行( -5 , -2 , -1 , +1 , +2 , +5 )操作中的一种,问从 a 转换为 b 最少需要多少次。 思路:贪心,对a和 b 的差取绝对值,先尽可能多的选操作 5 ,再尽可能多的选操作 2 ,最后再选操作 1 . #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int total,a,b; int num[3]={5,2,1}; cin>>total; while(total--){ cin>>a>>b; long long cha=abs(a-b); int ans=0; if(cha>0){ for(int i=0;i<3;i++){ ans+=cha/num[i]; cha%=num[i]; } } cout<<ans<<endl; } return 0; } View Code B. Fridge Lockers 题目数据范围被修改了,现在改为了m≤n,就很好写了 题意:给n个点,让建m条边,要求每个点至少有2个临边