A. Sequence with Digits(思维)

  • 题面
  • 题意:给出一个数 a 1 \small a_1 与构造次数 k \small k ,需要对 a 1 \small a_1 操作 k \small k 次,输出构造后的数 a k \small a_k
    操作过程见图解:
  • 解决思路:当有一位的数为 0 \small 0 时,其实后面的数都一样了,就可以跳出循环了。
  • AC代码
//优化
#pragma GCC optimize(2)
//C
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
//C++
#include<unordered_map>
#include<algorithm>
#include<iostream>
#include<istream>
#include<iomanip>
#include<climits>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
//宏定义
#define N 2010
#define DoIdo main
//#define scanf scanf_s
#define it set<ll>::iterator
//定义+命名空间
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 1e18;
const int maxn = 10 + 10;
using namespace std;
//全局变量
//函数区
ll max(ll a, ll b) { return a > b ? a : b; }
ll min(ll a, ll b) { return a < b ? a : b; }
ll get(ll x) {
	ll mi = 11, mx = 0;
	while (x) {
		ll t = x % 10;
		mi = min(mi, t);
		mx = max(mx, t);
		x /= 10;
	}
	return mi * mx;
}
//主函数
int DoIdo() {
 
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
 
 
	ll T;
	cin >> T;
 
	while (T--) {
		ll a1, k;
		cin >> a1 >> k;
		k--;
 
		while (k--) {
			ll val = get(a1);
			if (!val) break;
			a1 += val;
		}
 
		cout << a1 << endl;
	}
	return 0;
}
//分割线---------------------------------QWQ
/*
 
 
 
*/

猜你喜欢

转载自blog.csdn.net/qq_45739057/article/details/106209683