[codeforces 1355A] Sequence with Digits

题目见:1355A
题意:一个数a1,进行K次操作,每次加上a1各个位置上最大的数和最小的数的乘积。
思路:K有可能取到很大,如果单纯模拟绝对会超时。观察题目可以发现,a1进行有限次操作后,各个位置上最小数会变成0,这个时候答案就是不变的了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db cout<<"where"<<endl;
int main()
{
int t;
cin>>t;
while(t--)
{
ll a,n;
string b;
cin>>a>>n;
for(int j=1; j<n; j++)
{
b=to_string(a);
char MAX='0',MIN='9';
for(int i=0; i<b.size(); i++)
{
if(b[i]<MIN)
MIN=b[i];
if(b[i]>MAX)
MAX=b[i];
}
int MAXX=MAX-'0',MINN=MIN-'0';
if(MINN==0)
break;
a+=MAXX*MINN;
}
cout<<a<<endl;
}
return 0;
}
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2020-2024 Rye
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信