A. Number Transformation
一个构造技巧:令指数为 1 1 1。
#include <bits/stdc++.h>
using namespace std;
void solve()
{
int x,y;cin>>x>>y;
if(y%x){cout<<"0 0"<<'\n';return;}
else cout<<"1 "<<y/x<<'\n';
}
int main()
{
int t;cin>>t;
while(t--) solve();
return 0;
}
B. Dictionary
#include <bits/stdc++.h>
using namespace std;
void solve()
{
char a,b;cin>>a>>b;
int ans=(a-'a')*25;
if(b>a) ans+=b-'a',cout<<ans<<'\n';
else ans+=b-'a'+1,cout<<ans<<'\n';
}
int main()
{
int t;cin>>t;
while(t--) solve();
return 0;
}
C. Infinite Replacement
分情况讨论:
-
t = a t=\texttt{a} t=a,则替换是无效的,只有一种可能。
-
a ∈ t \texttt{a}\in t a∈t ,则可以无限替换。
-
其他情况, s s s 中的每一项都可以选择换 / 不换,共有 2 len ( s ) 2^{\operatorname{len}(s)} 2len(s) 种可能。
#include <bits/stdc++.h>
using namespace std;
void solve()
{
string s,t;cin>>s>>t;
if(t=="a"){cout<<"1\n";return;}
for(int i=0;i<t.length();i++) if(t[i]=='a'){cout<<"-1\n";return;}
cout<<(long long)pow(2,s.length())<<endl;
}
int main()
{
int t;cin>>t;
while(t--) solve();
return 0;
}
本文介绍了四个编程问题,涉及数制转换、字符处理、无限替换计数和字符串操作。每个部分展示了不同的算法策略,如检查条件并输出结果或计算可能的替换组合。
661

被折叠的 条评论
为什么被折叠?



