1 条题解

  • 0
    @ 2023-1-9 10:11:09

    目标是让 AA 尽可能上小下大,所以要尽可能让 BB 上大下小。倒序枚举,保持 BB 为单调增栈。如果现在的盘子比 BB 的栈顶要小,就把 BB 栈所有比当前盘子大的盘子全部移去 AA 栈。最后确认 AA 栈是否危险即可。

    #include <cstdio>
    #include <stack>
    using namespace std;
    int f[100005];
    stack<int> a, b;
    int main() {
        int n;
        while (scanf("%d", &n) != EOF) {
            for (int i = 1; i <= n; i++)
                scanf("%d", &f[i]);
            b.push(f[n]);
            for (int i = n - 1; i >= 1; i--) {
                while (!b.empty() && f[i] < b.top())
                    a.push(b.top()), b.pop();
                b.push(f[i]);
            }
            while (!b.empty())
                a.push(b.top()), b.pop();
            int t = a.top();
            bool flag = 1;
            a.pop();
            while (!a.empty()) {
                if (a.top() < t)
                    flag = 0;
                t = a.top();
                a.pop();
            }
            puts(flag ? "Y" : "J");
        }
        return 0;
    }
    
    • 1

    信息

    ID
    2
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者