A. Yet Another Two Integers Problem

https://codeforces.com/contest/1409/problem/A


思路:贪心,从最大的10步去贪,能贪就贪,不能贪心就找次小步

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5;
typedef long long LL;
LL p[15];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--)
  {
  	LL a,b;cin>>a>>b;
	LL cnt=fabs(a-b);
	for(LL i=10;i>=1;i--)
	{
		LL k=cnt/i;
		p[i]=k;
		cnt-=k*i;	
	}	 
	LL sum=0;
	for(LL i=1;i<=10;i++)
	{
		if(p[i]) sum+=p[i];	
	} 
	cout<<sum<<endl;
  } 
return 0;
}

猜你喜欢

转载自blog.csdn.net/zstuyyyyccccbbbb/article/details/108420960