第 8 场 小白入门赛

第 8 场 小白入门赛

第一题:

解题思路:

乘一下。

代码:

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

void solve()
{
    int cur = 2024;
    cur *= 2.5;
    cout << (int)cur << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

第二题:

解题思路:

自定义排序:比较a+bb+a的字符串大小,按升序排序。

代码:

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

bool cmp(string a, string b)
{
    string t1 = a + b;
    string t2 = b + a;
    return t1 < t2;
}

void solve()
{
    int n;
    cin >> n;
    vector<string> a;
    for (int i = 1; i <= n; i++)
    {
        string s;
        cin >> s;
        a.emplace_back(s);
    }
    sort(a.begin(), a.end(), cmp);
    for (auto s : a)
    {
        cout << s;
    }
    cout << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

第三题:

正确解题思路:

10就是求最后个位数是多少,对于这点,我们发现只要考虑09的高次幂的规律即可。打一下表能发现周期性。

赛时解法:

快速幂拆着做。

代码:

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

ll qmi(ll a, ll b)
{
    ll res = 1;
    while (b)
    {
        if (b & 1)
        {
            res = res * a % 10;
        }
        a = a * a % 10;
        b >>= 1;
    }
    return res;
}

void solve()
{
    ll x;
    cin >> x;
    string p;
    cin >> p;
    reverse(p.begin(), p.end());
    ll a = x;
    ll ans = 1;
    for (auto c : p)
    {
        int b = c - '0';
        if (b > 0)
        {
            ans = ans * qmi(a, b) % 10;
        }
        a = qmi(a, 10);
    }
    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

第四题:

解题思路:

递推。

a1=0a1=2时序列唯一。

对于a1=1,对x1=1x2=1分类讨论。

注意:判掉xi不为01的解法。

代码:

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

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n + 1), x(n + 1, 0);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    if (a[1] == 0)
    {
        for (int i = 3; i <= n; i++)
        {
            x[i] = a[i - 1] - (x[i - 1] + x[i - 2]);
        }
    }
    else if (a[1] == 1)
    {
        x[2] = 1;
        bool f = true;
        for (int i = 3; i <= n; i++)
        {
            x[i] = a[i - 1] - (x[i - 1] + x[i - 2]);
            if (x[i] < 0 || x[i] > 1)
            {
                f = false;
            }
        }
        if (x[n - 1] + x[n] != a[n] || !f)
        {
            x[1] = 1;
            x[2] = 0;
            for (int i = 3; i <= n; i++)
            {
                x[i] = a[i - 1] - (x[i - 1] + x[i - 2]);
            }
        }
    }
    else if (a[1] == 2)
    {
        x[1] = 1;
        x[2] = 1;
        for (int i = 3; i <= n; i++)
        {
            x[i] = a[i - 1] - (x[i - 1] + x[i - 2]);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << x[i] << " \n"[i == n];
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

第五题:

解题思路:

对于n=2n=3的情况特殊讨论。所有元素都要变得相同。

整个序列只要按升序排序,头两个数字和尾两个数字相同即合法。

代码:

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

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n + 1), cnt(110, 0);
    int mx = -1;
    int sx = -1;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        cnt[a[i]]++;
    }
    for (int i = 1; i <= n; i++)
    {
        if (cnt[i] == 0)
        {
            continue;
        }
        if (cnt[i] > mx)
        {
            sx = mx;
            mx = cnt[i];
        }
        else if (cnt[i] == mx)
        {
            sx = mx;
        }
        else if (cnt[i] > sx)
        {
            sx = cnt[i];
        }
    }
    sort(a.begin() + 1, a.end());
    if (n & 1)
    {
        if (n == 3)
        {
            cout << n - mx << "\n";
        }
        else
        {
            if (a[n - 1] != a[n] && a[1] != a[2])
            {
                if (a[n - 1] == a[n - 2] || a[2] == a[3])
                {
                    cout << 1 << "\n";
                }
                else
                {
                    cout << 2 << "\n";
                }
            }
            else if (a[n - 1] == a[n] && a[1] == a[2])
            {
                cout << 0 << "\n";
            }
            else
            {
                cout << 1 << "\n";
            }
        }
    }
    else
    {
        if (n == 2)
        {
            cout << (a[1] != a[2]) << "\n";
        }
        else
        {
            if (a[n - 1] != a[n] && a[1] != a[2])
            {
                if (a[n - 1] == a[n - 2] || a[2] == a[3])
                {
                    cout << 1 << "\n";
                }
                else
                {
                    cout << 2 << "\n";
                }
            }
            else if (a[n - 1] == a[n] && a[1] == a[2])
            {
                cout << 0 << "\n";
            }
            else
            {
                cout << 1 << "\n";
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

第六题:

解题思路:

可达的最小值到最大值之间的所有数都一定可以得到。

只要x在可达的最大值和最小值之间,那么就是可以恰好得到的。

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
#define fi first
#define se second
using piii = pair<ll, pair<ll, ll>>;
const ll inf = 1ll << 60;
using ull = unsigned long long;
// using i128 = __int128_t;
const int N = 210 + 10;
void solve()
{
    int n, x;
    cin >> n >> x;
    vector<int> a(n + 2);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    vector<vector<int>> dp(n + 2, vector<int>(2));
    dp[1][0] = dp[0][0] + a[1];
    dp[1][1] = dp[0][1] + a[1];
    for (int i = 2; i <= n + 1; i++)
    {
        dp[i][0] = min(dp[i - 1][0], dp[i - 2][0]) + a[i];
    }
    for (int i = 2; i <= n + 1; i++)
    {
        dp[i][1] = max(dp[i - 1][1], dp[i - 2][1]) + a[i];
    }
    if (dp[n + 1][0] <= x && x <= dp[n + 1][1])
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
posted @   value0  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
点击右上角即可分享
微信分享提示