前言:
这次训练是大一大二一起参加的训练,总体来说难度是有的,我和队友在比赛时间内就写出了四道题,之后陆陆续续又补了了三道题,还有一道题看了学长题解后感觉有点超出我的能力范围了,就留给以后的自己吧。话不多说,上正文。
正文:
Problem:A 幸运数字:
#include <bits/stdc++.h>
using namespace std;
int sum,ans;
int main()
{
int n,t;cin>>n;
for(int i=1;i<=n;i++){
sum=0;t=i;
while(1){
sum+=t%10;
if(t/10==0&&t%10==0)
break;
t=t/10;
}
if(i%sum==1) ans++;
}
cout<<ans<<endl;
return 0;
}
简单的签到题,直接枚举判断就行了。
Problem:B 子数组和:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1010;
LL a[N];
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
bool flag = 0;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
LL res = a[j] - a[i - 1];
if (res == k) {
flag = 1;
cout << i << " " << j;
return 0;
}
}
}
cout <