A. Sequence with Digits(思维)

  • 题面
  • 题意:给出一个数 a 1 \small a_1 a1与构造次数 k \small k k,需要对 a 1 \small a_1 a1操作 k \small k k次,输出构造后的数 a k \small a_k ak
    操作过程见图解:
  • 解决思路:当有一位的数为 0 \small 0 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
/*
 
 
 
*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值