A - Diagonal String
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
typedef long long LL;
char a[3][3];
int main() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> a[i][j];
}
}
for (int i = 0; i < 3; i++) cout << a[i][i];
cout << endl;
return 0;
}
B - Palindromic Numbers
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
typedef long long LL;
int a, b;
bool check(int num) {
char s[10];
int cnt = 0;
while (num) {
s[cnt++] = num % 10;
num /= 10;
}
for (int i = 0; i < cnt; i++) {
if (s[i] != s[cnt - 1 - i]) return false;
}
return true;
}
int main() {
cin >> a >> b;
int res = 0;
for (int i = a; i <= b; i++) {
if (check(i)) res++;
}
cout << res << endl;
return 0;
}
C - Flip,Flip, and Flip......
没看懂题,但是猜了个式子就a了....
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
typedef long long LL;
LL a, b;
int main() {
cin >> a >> b;
if (a >= 2) a -= 2;
if (b >= 2) b -= 2;
cout << a * b << endl;
return 0;
}
D - Remainder Reminder
给出n和k,问满足条件的a和b数对有多少个,条件是amodb大于等于k,且a和b都不大于n
对于b小于等于k来说,不可能符合条件,因为取模不可能到k
那么对于b大于k来说,取模大于等于k有(b - k)个可行的取值,即k k+1 k+2.....b-1
那么对于每个取值,都有n/b个a可以和他对应
所以对于每个b,都有(n / b) * (b - k)个数对可行,但是这里向下取整了,所以还要判断一下最后有多少取值可行
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, ans = 0;
cin >> n >> k;
if (k == 0)
ans = n * n;
else {
for (int b = k + 1; b <= n; b++) {
ans += (n / b) * (b - k);
if (n % b >= k) ans += n % b - k + 1;
}
}
cout << ans << endl;
return 0;
}