模拟题,直接用两个栈处理就行了,思路要清晰,不难
#include<cstdio>
#include<deque>
using namespace std;
int main()
{
int N, t;
deque<int> A;
deque<int> S;
while (scanf("%d", &N), N)
{
while (scanf("%d", &t), t)
{
A.clear();
S.clear();
for (int i = 1; i <= N; i++)
A.push_back(i);
while (A.front() != t)
{
S.push_back(A.front());
A.pop_front();
}
A.pop_front();
bool can = true;
for (int i = 2; i <= N; i++)
{
scanf("%d", &t);
if (!can)
continue;
if (!S.empty() && S.back() == t)
S.pop_back();
else
{
while (!A.empty() && A.front() != t)
{
S.push_back(A.front());
A.pop_front();
}
if (A.empty())
can = false;
else
A.pop_front();
}
}
puts(can ? "Yes" : "No");
}
puts("");
}
return 0;
}