題目鏈接
C. Digital Logarithm
題意
給兩個長度位
n
n
n的數(shù)組
a
a
a、
b
b
b,一個操作
f
f
f
定義操作
f
f
f為,
a
[
i
]
=
f
(
a
[
i
]
)
=
a
[
i
]
a[i]=f(a[i])=a[i]
a[i]=f(a[i])=a[i]的位數(shù)
求最少多少次操作可以使
a
、
b
a、b
a、b兩個數(shù)組變得完全相同
題解
性質(zhì):
對于任何數(shù),經(jīng)過兩次操作我們一定可以讓其變?yōu)?span id="n5n3t3z" class="katex--inline">
1
1
1,所以答案小于等于
2
n
2n
2n文章來源:http://www.zghlxwxcb.cn/news/detail-830129.html
然后我們考慮如何求最少的操作次數(shù),很自然的去考慮貪心,對于相同的數(shù)我們不去操作,只取操作不同的數(shù),這些不同的數(shù)一定需要進(jìn)行一次操作,然后操作完一次之后所有的數(shù)都被限制到 [ 1 , 9 ] [1,9] [1,9]之內(nèi),我們只需要統(tǒng)計(jì) [ 2 , 9 ] [2,9] [2,9]之內(nèi)的數(shù)還需要操作幾次即可。文章來源地址http://www.zghlxwxcb.cn/news/detail-830129.html
代碼
#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;
}
}
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;
}
到了這里,關(guān)于Educational Codeforces Round 135 (Rated for Div. 2)C. Digital Logarithm(思維)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!