Codeforces #667 (Div. 3) A. Yet Another Two Integers Problem

A. Yet Another Two Integers Problem(水题)

题目链接入口 Click here~~
在这里插入图片描述
题目描述
输入a,b两个数,通过a+k或者a-k操作k∈[1,10],将a变成b。
输入
第一行输入案例个数
第二行一次输入 a , b a,b
输出
输出在n次 a-- 或者 b-- 的操作后,a×b 最小的结果。
案例
输入案例

6
5 5
13 42
18 4
1337 420
123456789 1000000000
100500 9000

输出案例

0
3
2
92
87654322
9150

题解:
例子:13 → 23 → 33 → 42
先把A和B的是大小调整为,A≤B,由于k∈[1,10],所以可以直接枚举从10到1,详情看代码(水题,一看就懂的)

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define int ll
#define INF 0x3f3f3f3f
using namespace std;
int read()
{
	int w = 1, s = 0;
	char ch = getchar();
	while (ch < '0' || ch>'9') { if (ch == '-') w = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0';    ch = getchar(); }
	return s * w;
}
//------------------------ 以上是我常用模板与刷题几乎无关 ------------------------//
signed main()
{
	int t = read();
	while(t--)
	{
		int a = read();
		int b = read();
		if(a > b)
			swap(a ,b);
		int tmp = b - a;
		int cnt = 0;
		if (tmp / 10)
		{
			cnt = tmp / 10;
			tmp = tmp % 10;
		}
			
		if (tmp / 9)
		{
			cnt += tmp / 9;
			tmp = tmp % 9;
		}
			
		if (tmp / 8)
		{
			cnt += tmp / 8;
			tmp = tmp % 8;
		}
			
		if (tmp / 7)
		{
			cnt += tmp / 7;
			tmp = tmp % 7;
		}
		if (tmp / 6)
		{
			cnt += tmp / 6;
			tmp = tmp % 6;
		}
		if (tmp / 5)
		{
			cnt += tmp / 5;
			tmp = tmp % 5;
		}
		if (tmp / 4)
		{
			cnt += tmp / 4;
			tmp = tmp % 4;
		}
		if (tmp / 3)
		{
			cnt += tmp / 3;
			tmp = tmp % 3;
		}
		if (tmp / 2)
		{
			cnt += tmp / 2;
			tmp = tmp % 2;
		}
		cnt += tmp;
		printf("%d\n", cnt);
	}
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/m0_46272108/article/details/108417891