ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

牛客小白月赛44

2022-01-22 22:00:56  阅读:129  来源: 互联网

标签:10 int 44 ans ++ 牛客 while 小白月赛 scanf


A
双指针

#include <bits/stdc++.h>
#define PII pair<int, int>
using namespace std;
const int N = 2e5 + 10;
int T, n, d;
int a[N];
int main() {
    scanf("%d", &T);
    while (T -- ) {
        scanf("%d", &n);
        d = -1;
        vector<PII> ans;
        for (int i = 1; i <= n; i ++ )  cin >> a[i];
        for (int i = 1; i <= n; ) {
            int j = i + 1;
            while (j <= n && a[j] >= a[j - 1])  j ++;
            d = max(d, a[j - 1] - a[i]);
            i = j;
        }
        for (int i = 1; i <= n; ) {
            int j = i + 1;
            while (j <= n && a[j] >= a[j - 1])  j ++;
            if (d == a[j - 1] - a[i])   ans.push_back({i, j - 1});  
            i = j;
        }
        for (auto x : ans)
            printf("%d %d ", x.first, x.second);
        puts("");
    }
    return 0;
}

B
暴力

#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int T, n, m;
char s[N];
char a[N][N];
int main() {
    scanf("%d", &T);
    while (T -- ) {
        int ans = 0;
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= n; i ++ ) {
            scanf("%s", s + 1);
            for (int j = 1; j <= m; j ++ ) 
                a[i][j] = s[j];
        }
        for (int i = 1; i <= n; i ++ ) 
            for (int j = 1; j <= m; j ++ ) 
                if (a[i][j] == '*') 
                    for (int i1 = -1; i1 <= 1; i1 ++ ) 
                        for (int j1 = -1; j1 <= 1; j1 ++ ) 
                            if (i + i1 >= 1 && i + i1 <= n && j + j1 <= m && j + j1 >= 1 && a[i + i1][j + j1] != '*')
                                a[i + i1][j + j1] = 'Z';
        for (int i = 1; i <= n; i ++ ) 
            for (int j = 1; j <= m; j ++ ) 
                if (a[i][j] == 'P')
                    ans ++;
        printf("%d\n", ans);
    }
    return 0;
}

C
根据题意模拟

#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int T, n, r, g, ex;
int m, m1, m2;
int main() {
    scanf("%d", &T);
    while (T -- ) {
        scanf("%d%d.%d", &n, &m1, &m2);
        ex = 0;
        m = (m1 - 1) * 100 + m2 * 10;
        while (n) {
            r = n * 100, g = min(10000, n * m);
            n = r / 200, ex += r / 10;
            ex += g / 10;
        } 
        printf("%d\n", ex);
    }
    return 0;
}

D
简单数学

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 998244353;
int T, p, ans;
int len1, len2;
string s1, s2;
signed main() {
    cin >> T;
    while (T -- ) {
        p = 1;
        ans = 0;
        cin >> s1 >> s2;
        len1 = s1.size(), len2 = s2.size();
        reverse(s1.begin(), s1.end());
        reverse(s2.begin(), s2.end());
        for (int i = 0; i < len1; i ++ ) {
            int k = s1[i] - '0';
            ans = (ans + k * p % MOD * len2) % MOD;
            p = (p * 10) % MOD;
        }
        p = 1;
        for (int i = 0; i < len2; i ++ ) {
            int k = s2[i] - '0';
            ans = (ans + k * p % MOD * len1) % MOD;
            p = (p * 10) % MOD;
        }
        cout << ans << endl;
    }
    return 0;
}

E
找到所有黑点的数量后,\(C_{cnt}^{2}\)

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3e6 + 10;
int T, n, res;
bool st[N];
int h[N], e[N * 2], ne[N * 2], idx;
struct node {
    int ver, d;
};
signed main() {
    scanf("%lld", &T);
    while (T -- ) {
        scanf("%lld", &n);
        int max_d = 1;
        idx = 0, res = 0;
        for (int i = 1; i <= n; i ++ )  st[i] = 0;
        for (int i = 1; i <= n; i ++ )  h[i] = -1;
        function<void(int, int)> add = [&](int a, int b) {
            e[idx] = b, ne[idx] = h[a], h[a] = idx ++;
        };
        for (int i = 1; i < n; i ++ ) {
            int a, b;
            scanf("%lld%lld", &a, &b);
            add(a, b), add(b, a);
        }
        function<void()> bfs = [&]() {
            queue<node> q;
            q.push({1, 1});
            st[1] = 1;
            while (q.size()) {
                auto t = q.front();
                q.pop();
                int u = t.ver, step = t.d;
                if (step % 2 == 1)    res ++;
                for (int i = h[u]; i != -1; i = ne[i]) {
                    int j = e[i];
                    if (st[j])    continue;
                    q.push({j, step + 1});
                    st[j] = true;
                }
            }
        };
        bfs();
        printf("%lld\n", res + res * (res - 1) / 2);
    }
    return 0;
}

F
贪心,如果最长的数量小于总长的一半则所有点都成立
否则,只有在最长链上的点才成立,用最长链的长度减去两端不满足条件的即可

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 10;
int T, n, sum, maxx;
int a[N];
signed main() {
    scanf("%lld", &T);
    while (T -- ) {
        scanf("%lld", &n);
        sum = 0, maxx = 0;
        for (int i = 1; i <= n; i ++ )  
            scanf("%lld", &a[i]), sum += a[i], maxx = max(maxx, a[i]);
        if (maxx <= sum - maxx)
            printf("%lld\n", sum);
        else
            printf("%lld\n", maxx - (maxx - sum / 2 - 1) * 2);
    }
    return 0;
}

标签:10,int,44,ans,++,牛客,while,小白月赛,scanf
来源: https://www.cnblogs.com/Angels-of-Death/p/15835208.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有