1 条题解
-
0
目标是让 尽可能上小下大,所以要尽可能让 上大下小。倒序枚举,保持 为单调增栈。如果现在的盘子比 的栈顶要小,就把 栈所有比当前盘子大的盘子全部移去 栈。最后确认 栈是否危险即可。
#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
- 上传者