Educational Codeforces Round 135 (Rated for Div. 2)C. Digital Logarithm(思维)

题目链接

C. Digital Logarithm

题意

image
给两个长度位n的数组ab,一个操作f
定义操作f为,a[i]=f(a[i])=a[i]的位数
求最少多少次操作可以使ab两个数组变得完全相同

题解

性质:
对于任何数,经过两次操作我们一定可以让其变为1,所以答案小于等于2n

然后我们考虑如何求最少的操作次数,很自然的去考虑贪心,对于相同的数我们不去操作,只取操作不同的数,这些不同的数一定需要进行一次操作,然后操作完一次之后所有的数都被限制到[1,9]之内,我们只需要统计[2,9]之内的数还需要操作几次即可。

代码

#include <bits/stdc++.h> 
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back

using namespace std;
const int N=1e5+10;


void solve()
{
	string s;cin>>s;
	if(s.find('0')!=s.npos){
		cout<<"YES"<<endl;
		cout<<0<<endl;
		return;
	}
	rep(i,0,s.size()-1){
		rep(j,i+1,s.size()-1){
			rep(k,j+1,s.size()-1){
				int a=s[i]-'0',b=s[j]-'0',c=s[k]-'0';
				if((a*100+b*10+c)%8==0){
					cout<<"YES"<<endl;
					cout<<s[i]<<s[j]<<s[k]<<endl;
					return;
				}
			}
			int a=s[i]-'0',b=s[j]-'0';
			if((a*10+b)%8==0){
				cout<<"YES"<<endl;
				cout<<s[i]<<s[j]<<endl;
				return;
			}
		}
		int c=s[i]-'0';
		if(c%8==0){
			cout<<"YES"<<endl;
			cout<<s[i]<<endl;
			return;2024-02-11 16:01:40 星期日
		}
	}
	cout<<"NO"<<endl;
}

signed main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//   	freopen("1.in", "r", stdin);
  	int _;
//	cin>>_;
//	while(_--)
	solve();
	return 0;
}
posted @   cxy8  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
点击右上角即可分享
微信分享提示