【M Contest-Div.3】#7 题解
A. Array Stats 题解
题面
根据题意,题目给出你
你应求出
思路
按照题面暴力即可。
AC Code
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k,a,ans1,ans2=1,ans3;
bool f;
signed main(){
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a;
if(a>k)ans1+=a;
if(a==k)ans2*=a,f=1;
if(a<k)ans3^=a;
}
cout<<ans1<<' '<<ans2<<' '<<ans3;
return 0;
}
代码来自 @mengnn。
注意
-
由于
1\le k\le10 且1\le a_i\le10 ,所以计算乘积时的答案最大为10^{10} ,需要开long long。 -
如果没有
a_i=k ,便没有乘积,理应输出0。
复杂度
时间复杂度和空间复杂度均为
B. Mod Equation 题解
题面
根据题意,题目给出你
你需要求出以下方程的最小正整数解
思路
不难观察到当
所以
由于
所以
AC Code
#include<bits/stdc++.h>
using namespace std;
int a,b,c,ans=1;
int main(){
cin>>a>>b>>c;
while (true){
int res=a*ans+(ans%b);
if (res==c) break;
++ans;
if (a*ans>c){ans=-1;break;}
}
cout<<ans<<'\n';
return 0;
}
代码来自 @mengnn。
复杂度
时间复杂度
由于
空间复杂度
明显复杂度为
C. Digit Sequence 题解
题面
根据题意,共询问
前
思路
个位上的
十位上的
百位上的
以此类推...
我们便知道规律大概率和
如果我们把
我们补上前导零,得到:
我们便得出
思路很清晰了,直接
AC Code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e4+10;//较大数即可
ll x;
int tot;
int T;
int ans[N];
inline void solve(){
while(x){
ans[++tot]=x%3;
x/=3;
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>T;
while(T--){
tot=0;
cin>>x;
if(x==1){
cout<<0<<'\n';
continue;
}
x--;
solve();
for(int i=tot;i>=1;i--){//由于求进制时自动反转,所以我们需要先反转回去。
if(ans[i]==0) cout<<0;
else if(ans[i]==1) cout<<2;
else cout<<5;
}
cout<<'\n';
}
return 0;
}
代码来自 @SP_beyond_xxxx。
复杂度
时间复杂度
计算部分复杂度为
空间复杂度
我们需要存储并反转答案,所以
D. GCD And LCM 题解
题面
给你一个
:::info[
这是一个条件语句。
设
则当
:::
思路
对于前
对于前
代入原式,得
移项得
由于
我们枚举所有奇偶性为正的完全立方数即可。
由于
对于所有数据。
AC Code
代码来自 @mengnn。