24.04洛谷语言入门月赛(题解)

24.04洛谷语言入门月赛

\rightarrow赛后一定要补题!!!

A.疯狂大减价

#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    if (n > 200)
        n -= 70;
    else if (n > 100)
        n -= 20;
    cout << n;
    return 0;
}

B.ZngivaeL 的中考

#include <bits/stdc++.h>

using namespace std;
int a[4];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
        a[s[i] - 'A']++;
    // for(int i=0;i<4;i++) cout<<a[i]<<" ";
    // cout<<'\n';
    if (a[0] + a[1] == 4 && a[0] != 0)
        cout << "I'm so happy.";
    else if (a[0] + a[1] + a[2] == 4)
        cout << "This is ok.";
    else
        cout << "Never give up.";
    return 0;
}

C.游乐场

#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &p : a)
        cin >> p;
    int sum = 0, res = 0;
    for (int i = 0; i < n; i++)
    {
        if (i == 0)
            sum = min(50, a[i]);
        else
            sum = min(50, sum + a[i] - a[i - 1]);
        res += sum / 8;
        sum %= 8;
    }
    cout << res;
    return 0;
}

这道题不要忘记第一次去游乐场时,前面获得零花钱很可能会超过50,这一点就是我比赛期间没想到的,到时一直在wa,赛后重新思考才反应过来┭┮﹏┭┮

D.吃苹果

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 10;
int a[N];
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    sort(a + 1, a + 1 + n);
    cout << a[1] + a[n];
    return 0;
}

E.天上的气球

#include <bits/stdc++.h>

using namespace std;
const int N = 1e3 + 10;
pair<int, int> a[N][N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    while (k--)
    {
        int x, y, h, c;
        cin >> x >> y >> h >> c;
        if (!a[x][y].second || a[x][y].first > h)
            a[x][y] = make_pair(h, c);
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
            cout << a[i][j].second << " ";
        cout << '\n';
        ;
    }
    return 0;
}

F.神秘排列

#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 10;
int a[N], b[N], f[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        f[a[i]]++;
        if (f[a[i]] > 1)
        {
            cout << "NO";
            return 0;
        }
        b[a[i]] = i;
    }
    // for(int i=1;i<=n;i++) cout<<b[i]<<" ";
    // cout<<'\n';
    for (int i = 1; i <= n; i++)
    {
        if (b[i] != a[i])
        {
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
    return 0;
}

G.道法考试

#include <bits/stdc++.h>

using namespace std;

const int N = 1e3 + 10, M = 2e3 + 10;
int a[M];
set<int> s[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            int x;
            cin >> x;
            s[i].insert(x);
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        int t = 0;
        for (int j = 1; j <= a[i]; j++)
        {
            int x;
            cin >> x;
            t += s[i].count(x);
        }
        if (t == m)
            ans += 2;
    }
    cout << ans;
    return 0;
}

H.非众数

#include <bits/stdc++.h>

using namespace std;

queue<string> q;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        for (int j = i; j < s.size(); j++)
            q.push(s.substr(i, j - i + 1));
    }
    int ans = 0;
    while (q.size())
    {
        s = q.front();
        q.pop();
        int a[27] = {0}, mx = 0;
        for (int i = 0; i < s.size(); i++)
            mx = max(mx, ++a[s[i] - 'a']);
        if (mx <= s.size() / 2)
            ans++;
    }
    cout << ans;
    return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

July.19th

感谢各位对我的支持

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

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

打赏作者

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

抵扣说明:

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

余额充值