T1:Long Loong
模拟
代码实现
n = int(input())
print('L'+'o'*n+'ng')
T2:CTZ
__builtin_ctz
或 countr_zero
代码实现
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned n;
cin >> n;
cout << countr_zero(n) << '\n';
return 0;
}
T3:Even Digits
\(5\) 进制数
代码实现
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n;
cin >> n;
n--;
if (n == 0) {
puts("0");
return 0;
}
string s;
while (n) {
s += '0'+(n%5*2);
n /= 5;
}
reverse(s.begin(), s.end());
cout << s << '\n';
return 0;
}
T4:Pyramid
分别求出以当前点为中心向左右两边延伸的半径,可以 \(O(n)\) 递推求
代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
a.push_back(0);
a.insert(a.begin(), 0);
n += 2;
vector<int> dl(n), dr(n);
for (int i = 1; i < n; ++i) {
dl[i] = min(dl[i-1]+1, a[i]);
}
for (int i = n-2; i >= 0; --i) {
dr[i] = min(dr[i+1]+1, a[i]);
}
int ans = 0;
rep(i, n) {
int now = min(dl[i], dr[i]);
ans = max(ans, now);
}
cout << ans << '\n';
return 0;
}