首页 > 其他分享 >ABC336

ABC336

时间:2024-01-14 23:55:06浏览次数:43  
标签:dl int cin long ABC336 using dr

T1:Long Loong

模拟

代码实现
n = int(input())
print('L'+'o'*n+'ng')

T2:CTZ

__builtin_ctzcountr_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\) 进制数

image

代码实现
#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;
}

标签:dl,int,cin,long,ABC336,using,dr
From: https://www.cnblogs.com/Melville/p/17964487

相关文章