PDD 5.11笔试

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

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<string> s(n + 1);
        vector<int> sz(n + 1, 0);
        for (int i = 1; i <= n; i++) cin >> s[i], sz[i] = s[i].size();
        int ans = 1, cnt = 1;
        for (int i = 2; i <= n; i++) {
            if (sz[i] > sz[i - 1]) {
                cnt++;
            } else if (sz[i] == sz[i - 1]) {
                if (s[i] >= s[i - 1]) cnt++;
                else {
                    ans = max(ans, cnt);
                    cnt = 1;
                }
            } else {
                ans = max(ans, cnt);
                cnt = 1;
            }
        }
        ans = max(ans, cnt);
        cout << ans << "\n";
    }
}
// 64 位输出请用 printf("%lld")
B
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0, bj = 0;
    int now = 0, l = 0, r = 0;
    vector<pair<char, int>> v;
    vector<array<int, 2>> va;
    for (auto c : s) {
        now++;
        if (!v.empty()) {
            if (c == '(') {
                if (bj) {
                    while (!va.empty() && l < va.back()[0]) va.pop_back();
                    va.push_back({l, r});
                    bj = 0;
                }
                v.emplace_back(c, now);
            } else {
                if (v.back().first == '(') {
                    bj = 1;
                    l = v.back().second;
                    r = now;
                    v.pop_back();
                } else {
                    if (bj) {
                        while (!va.empty() && l < va.back()[0]) va.pop_back();
                        va.push_back({l, r});
                        bj = 0;
                    }
                    v.emplace_back(c, now);
                }
            }
        } else {
            if (bj) {
                while (!va.empty() && l < va.back()[0]) va.pop_back();
                va.push_back({l, r});
                bj = 0;
            }
            v.emplace_back(c, now);
        }
    }
    if (bj) {
        while (!va.empty() && l < va.back()[0]) va.pop_back();
        va.push_back({l, r});
        bj = 0;
    }
    ans = v.size();
    for (int i = 1; i < va.size(); i++) {
        if (va[i][0] != (va[i - 1][1] + 1)) {
            ans++;
        }
    }
    if(va.size()) ans++;
    cout << ans;
}
// 64 位输出请用 printf("%lld")
C
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[N], b[N];
int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) cin >> a[i];
    vector<vector<array<int, 2>>> v1, v2;
    for (int i = 1; i <= n; i++) {
        int k; cin >> k;
        vector<array<int, 2>> t;
        for (int i = 1; i <= k; i++) {
            int x, y; cin >> x >> y;
            t.push_back({x, y});
        }
        v1.push_back(t);

        cin >> k;
        t.clear();
        for (int i = 1; i <= k; i++) {
            int x, y; cin >> x >> y;
            t.push_back({x, y});
        }
        v2.push_back(t);
    }
    while (true) {
        bool tj = 1;
        for (int i = 0; i < n; i++) if(!b[i]) {
            bool ok = 1;
            for (auto [x, y] : v2[i]) {
                if (a[x] < y) ok = 0;
            }
            if (ok) {
                b[i] = 1;
                for (auto [x, y] : v1[i]) {
                    a[x] += y;
                }
                tj = 0;
            }
        }
        if (tj) break;
    }
    vector<int> ans;
    for (int i = 0; i < n; i++) if(!b[i]) ans.push_back(i + 1);
    cout << ans.size() << "\n";
    for (auto c : ans) {
        cout << c << " ";
    }
}
// 64 位输出请用 printf("%lld")
D 不会
全部评论
感谢 从你的代码中找到了我的错误原因
点赞 回复 分享
发布于 05-11 22:28 广东
三道都全过了吗?
点赞 回复 分享
发布于 05-11 22:04 四川

相关推荐

05-11 21:28
已编辑
门头沟学院 C++
点赞 评论 收藏
分享
三题看不懂四题不明白二题无法AC&nbsp;&nbsp;T=int(input())&nbsp;for&nbsp;_&nbsp;in&nbsp;range(T):&nbsp;n=int(input())&nbsp;s=input().split()&nbsp;k,mx=1,1&nbsp;for&nbsp;i&nbsp;in&nbsp;range(len(s)-1):&nbsp;if&nbsp;len(s[i])&lt;len(s[i+1]):&nbsp;k+=1&nbsp;elif&nbsp;len(s[i])==len(s[i+1]):&nbsp;if&nbsp;s[i]&lt;=s[i+1]:&nbsp;k+=1&nbsp;else:&nbsp;mx=max(mx,k)&nbsp;k=1&nbsp;mx=max(mx,k)&nbsp;else:&nbsp;mx=max(mx,k)&nbsp;k=1&nbsp;mx=max(mx,k)&nbsp;print(mx)&nbsp;=====&nbsp;##过了...
恭喜臭臭猴子:第二题用栈就行。合法的括号直接出栈了,剩下的是不合法的,肯定都得一个一个走。出入栈的过程中得记下进栈的括号的下标。最后栈里剩下的括号如果相邻两个的下标不连续,说明它们中间有一个合法的括号序列被出栈,结果加一
投递拼多多集团-PDD等公司10个岗位 > 拼多多求职进展汇总 笔试
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务