DIV4(小菜鸡Codechef)

youhualiuh / 2024-02-01 / 原文

Advitiya

思路:

判断 16 17 18 的时候输出 ADVITIYA 不是就输出 WAITING FOR ADVITIYA

Code:

#include <bits/stdc++.h>

using namespace std;
    
signed main()
{
    int n; cin >> n;
    if (n >= 16 && n <= 18) {
        cout << "ADVITIYA\n";
    }
    else {
        cout << "WAITING FOR ADVITIYA\n";
    }
    return 0;
}

  

Judged

思路:

有5个裁判 只要超过 或 等于4人就输出YES 否则 NO

Code:

#include <bits/stdc++.h>
using namespace std;
    
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int  t; cin >> t;
    while (t--)
    {
        int x, cnt = 0;;
        for (int i = 1; i <= 5; ++i) {
            cin >> x;
            cnt += x;
        }
        cout << (cnt >= 4 ? "YES\n" : "NO\n");
    }
    
    return 0;
}

  

Cookie Day

思路:

饼干要让每个人都获得至少一个,如果有一个人没获得就输出-1,并且是在一个罐子里分配,因此去遍历这个x(饼干数量),得出公式 minn = min(minn, x / m * m); (x > m)

Code:

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

typedef long long ll;

int main() {
    ll t; cin >> t;
    while (t--)
    {
        ll n, m; cin >> n >> m;
        ll minn = 1e9 + 1;
        ll x;
        bool flag2 = 0;
        for (int i = 1; i <= n; ++i)
        {
            cin >> x;
            if (x < m) {
                continue;
            }
            else {
                minn = min(minn, x - (x / m) * m);
                flag2 = 1; 
            }
        }
        if (flag2) cout << minn << '\n';
        else cout << -1 << '\n';
    }
  return 0; }

  

Another Good String

思路:

去寻找每一次的最长连续字符 先输出没有插入字符时的数量 在去统计每一次插入时的最大连续字符,数据极限, 我采用前缀和实现Code

Code:

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

typedef long long ll;
ll cnt;
const int N = 2e5 + 5;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll t; cin >> t;
    while (t--)
    {
        ll n, m; string s;
        cnt = 1;
        cin >> n >> m >> s;
        ll a[N] = {1};
        for (int i = 1; i < n; i++) 
        {
            if (s[i] == s[i - 1]) {
                cnt++;//cnt
                if (cnt > a[i - 1]) {
                    a[i] = a[i - 1] + 1;
                }
                else {
                    a[i] = a[i - 1];
                }
            }
            else {
                a[i] = a[i - 1];
                cnt = 1;
            }
        }
        cout << a[n - 1] << ' ';
        while (m--) {
            char ck; cin >> ck;
            s += ck;
            n ++;
            if (s[n - 1] == s[n - 2]) {
                cnt++;
                if (cnt > a[n - 2]) {
                    a[n - 1] = a[n - 2] + 1;
                }
                else {
                    a[n - 1] = a[n - 2];
                }
            }
            else {
                cnt = 1;
                a[n - 1] = a[n - 2];
            }
            cout << a[n - 1] << ' ';
        } 
        cout << '\n';
    }
    
    return 0;
}