AtCoder Beginner Contest 252

A - ASCII code

// shiran
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9+7;
const int N = 200010, M = 300010;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin >> n;
    char c = 'a' + n - 97;
    printf("%c", c);
    return 0;
}

// shiran
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9+7;
const int N = 200010, M = 300010;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

int a[N];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    int maxn = 0;
    rep(i, 1, n + 1) cin >> a[i], maxn = max(maxn, a[i]);
    
    set<int> S;
    rep(i, 1, n + 1)
        if (a[i] == maxn)
            S.insert(i);
    while (k -- )
    {
        int x;
        cin >> x;
        if (S.count(x))
        {
            puts("Yes");
            return 0;
        }
    }
    puts("No");
    return 0;
}

C - Slot Strategy

// shiran
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9+7;
const int N = 210, M = 300010;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

int n;
int t[N];
string s[N];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n;
    rep(i, 1, n + 1) cin >> s[i];
    
    int res = 0x3f3f3f3f;
    rep(i, 0, 10)
    {
        map<int, int> mp;
        int k = 1, ans = 0;
        rep(j, 1, n + 1)
        {
            int p = s[j].find(to_string(i));
            if (mp[p])
            {
                ans = max(ans, 10 * mp[p] + p);
                mp[p] ++ ;
            }
            else
            {
                mp[p] ++ ;
                ans = max(ans, p);
            }
        }
        res = min(res, ans);
    }
    
    cout << res << endl;
    return 0;
}

D - Distinct Trio

// shiran
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9+7;
const int N = 200010, M = 300010;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

int n;
ll a[N], s[N];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    
    rep(i, 1, n + 1) cin >> a[i], s[a[i]] ++ ;
    rep(i, 1, N) s[i] += s[i - 1];
    
    ll ans = 0;
    rep(i, 1, n + 1)
    {
        ans += 1ll * s[a[i] - 1] * (n - s[a[i]]); 
    }
    printf("%lld", ans);
    return 0;
}

E - Road Reduction

// shiran
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<ll, int> PII;
const int mod = 1e9+7;
const int N = 200010, M = N * 2;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

int n, m;
struct Edge
{
    ll to, cost, idx;
};
vector<Edge> g[N];
bool st[N];
int ans[M];

void dijkstra()
{
    vector<ll> dist(n + 1, 1ll<<60);
    dist[1] = 0;
    
    priority_queue<PII, vector<PII>, greater<PII>> q;
    q.push({0, 1});
    
    while (q.size())
    {
        auto t = q.top();
        q.pop();
        
        int ver = t.se;
        if (st[ver]) continue;
        st[ver] = true;
        
        for (auto [vv, c, i] : g[ver])
        {
            if (dist[vv] > dist[ver] + c)
            {
                dist[vv] = dist[ver] + c;
                ans[vv] = i;
                q.push({dist[vv], vv});
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;

    rep(i, 1, m + 1)
    {
        int a, b, c;
        cin >> a >> b >> c;
        g[a].pb({b, c, i});
        g[b].pb({a, c, i});
    }
    
    dijkstra();
    rep(i, 1, m + 1)
        if (ans[i])
            printf("%d ", ans[i]);
    
    return 0;
}

F - Bread

// shiran
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9+7;
const int N = 200010, M = 300010;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

int n;
ll k;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    priority_queue<ll, vector<ll>, greater<ll>> q;
    
    cin >> n >> k;
    ll ans = 0;
    rep(i, 1, n + 1)
    {
        ll x;
        cin >> x;
        k -= x;
        q.push(x);
    }
    
    if (k > 0)
    {
        q.push(k);
    }
    while (q.size() > 1)
    {
        ll a = q.top();
        q.pop();
        ll b = q.top();
        q.pop();
        ans += (a + b);
        q.push(a + b);
    }
    printf("%lld", ans);
    return 0;
}

G - Pre-Order

WA了,其实序列的顺序还是没有考虑很清楚…弄明白了来补题

// shiran
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 998244353;
const int N = 510, M = 300010;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

int n;
int pre[N];
ll f[N][N];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    rep(i, 1, n + 1) cin >> pre[i];
    
    for (int len = 1; len <= n; len ++ )
    {
        for(int l = 1; l + len - 1 <= n; l ++ )
        {
            int r = l + len - 1;
            if (len == 1) f[l][r] = 1;
            else
            {
                for (int k = l + 1; k <= r; k ++ )
                    if (pre[l] < pre[k])
                        f[l][r] = (f[l][r] + f[l][k - 1] * f[k][r]) % mod;
            }
        }
    }
    printf("%lld\n", f[1][n]);
    
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Shirandexiaowo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值