WA on #2 求调
查看原帖
WA on #2 求调
741244
Eason_cyx大愚若智楼主2024/8/21 15:21

rt,CF 显示 wrong answer 57th numbers differ - expected: '3', found: '2',但是因为长度限制看不到错的数据,求助

#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main() {
    int t; cin >> t;
    while(t--) {
        int n; cin >> n;
        for(int i = 1;i <= n;i++) cin >> a[i];
        //1 是根节点
        int pos = 2/*当前处理的点*/,last = -1/*上一个点*/,lst_leaf = 1/*上一层的叶子数量*/,now_leaf = 0/*这一层的叶子数量*/,depth = 1/*当前深度*/;
        while(pos <= n) {
            // cout << pos << ' ' << a[pos] << ' ' << last << endl;
            if(a[pos] > last) {
                last = a[pos];
                now_leaf++;
            }
            else {
                lst_leaf--;
                if(lst_leaf == 0) {
                    //切换到下一层
                    last = a[pos];
                    lst_leaf = now_leaf;
                    now_leaf = 1;
                    depth++;
                }
                else {
                    last = -1;
                }
            }
            pos++;
        }
        cout << depth << endl;
    }
    return 0;
}
2024/8/21 15:21
加载中...