牛客小白月赛88

牛客小白月赛88

A

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
typedef double db;
#define fi first
#define se second
using i128 = __int128_t;
using piii = pair<ll, pair<ll, ll>>;
const ll inf = 1ll << 60;
const int N = 1e5 + 10;

void solve()
{
    int x;
    cin >> x;
    int n;
    cin >> n;
    int mx = 0;
    string c;
    for (int i = 1; i <= n; i++)
    {
        string s;
        int x;
        cin >> s >> x;
        if (x > mx)
        {
            mx = x;
            c = s;
        }
    }
    int cnt = (x + mx - 1) / mx;
    if (cnt > 1000)
    {
        puts("-1");
    }
    else
    {
        for (int i = 1; i <= cnt; i++)
        {
            cout << c;
        }
    }
}

int main()
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

B

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
typedef double db;
#define fi first
#define se second
using i128 = __int128_t;
using piii = pair<ll, pair<ll, ll>>;
const ll inf = 1ll << 60;
const int N = 1e5 + 10;
char g[100][100];
void solve()
{
    int a = -1;
    int b = -1;
    char c = 's';
    char last;
    for (int i = 1; i <= 5; i++)
    {
        for (int j = 1; j <= 10; j++)
        {
            cin >> g[i][j];
            if (g[i][j] >= '0' && g[i][j] <= '9' && last != '=')
            {
                if (a == -1)
                {
                    a = g[i][j] - '0';
                }
                else if (b == -1)
                {
                    b = g[i][j] - '0';
                }
            }
            else if (c == 's' && g[i][j] != ' ' && g[i][j] != '*')
            {
                c = g[i][j];
            }
            last = g[i][j];
        }
    }
    if (c == '&')
    {
        cout << (a && b) << endl;
    }
    else if (c == '>')
    {
        cout << (a | b) << endl;
    }
    else
    {
        cout << (!a) << endl;
    }
}

int main()
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

C

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
typedef double db;
#define fi first
#define se second
using i128 = __int128_t;
using piii = pair<ll, pair<ll, ll>>;
const ll inf = 1ll << 60;
const int N = 1e5 + 10;

void solve()
{
    set<array<int, 2>> s;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int a, b;
        cin >> a >> b;
        if (b >= 1)
        {
            s.insert({a, b - 1});

            if (b >= 3)
            {
                s.insert({a, b - 3});
                if (b >= 5)
                {
                    s.insert({a, b - 5});
                }
                else
                {
                    s.insert({a - 1, b + 60 - 5});
                }
            }
            else
            {
                s.insert({a - 1, b - 3 + 60});
                s.insert({a - 1, b + 60 - 5});
            }
        }
        else
        {
            s.insert({a - 1, b - 1 + 60});
            s.insert({a - 1, b - 3 + 60});
            s.insert({a - 1, b + 60 - 5});
        }
    }
    cout << s.size() << endl;
    for (auto t : s)
    {
        cout << t[0] << ' ' << t[1] << endl;
    }
}

int main()
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

D

解题思路:

dp[i][j]:inj

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
typedef double db;
#define fi first
#define se second
using i128 = __int128_t;
using piii = pair<ll, pair<ll, ll>>;
const ll inf = 1ll << 60;
const int N = 5e3 + 10;
bool dp[N][N];
void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m + 1);
    ll s = 0;
    for (int i = 1; i <= m; i++)
    {
        cin >> a[i];
        a[i] = a[i] % n;
        s += a[i];
    }
    if (s % n == 0)
    {
        puts("YES");
        return;
    }
    dp[0][0] = true;
    for (int i = 1; i <= m; i++)
    {
        for (int j = 0; j < n; j++)
        {
            dp[i][j] = dp[i - 1][(j + a[i]) % n] | dp[i - 1][(j - a[i] + n) % n];
        }
    }
    if (dp[m][0])
    {
        puts("YES");
        return;
    }
    puts("NO");
}

int main()
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

E

解题思路:

从后往前映射变换。

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
typedef double db;
#define fi first
#define se second
using i128 = __int128_t;
using piii = pair<ll, pair<ll, ll>>;
const ll inf = 1ll << 60;
const int N = 1e6 + 10;

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    vector<pii> q(m + 1);
    map<int, int> t;
    for (int i = 1; i <= m; i++)
    {
        cin >> q[i].fi >> q[i].se;
        t[q[i].fi] = q[i].fi;
        t[q[i].se] = q[i].se;
    }
    for (int i = m; i > 0; i--)
    {
        t[q[i].fi] = t[q[i].se];
    }
    for (int i = 1; i <= n; i++)
    {
        if (t.find(a[i]) == t.end())
        {
            cout << a[i] << ' ';
        }
        else
        {
            cout << t[a[i]] << ' ';
        }
    }
    cout << endl;
}

int main()
{
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
posted @   value0  阅读(34)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示