#include <cstdio>
#include <iostream>
#include <stack>
using namespace std;
int main()
{
//freopen("514_in.txt","r+",stdin);
//freopen("514_out.txt","w+",stdout);
int n, i, val;
bool found;
while (scanf("%d",&n) && n)
{
while (1)
{
scanf("%d",&val);
if (!val)
{
printf("\n");
break;
}
stack<int> b;
stack<int> s;
b.push(val);
for (i=1 ; i<n ; i++)
{
scanf("%d",&val);
b.push(val);
}
for (i=n, found=true ; i>=1 && found ; i--)
{
if (!s.empty() && i==s.top())
{
s.pop();
continue;
}
while (1)
{
if (!b.empty() && i!=b.top())
{
val = b.top();
s.push(val);
b.pop();
found=false;
} else if (!b.empty() && i==b.top())
{
b.pop();
found=true;
break;
} else {
found=false;
break;
}
}
}
if (found) printf("Yes\n");
else printf("No\n");
}
}
return 0;
}
Friday, August 19, 2011
[UVa] 514 - Rails
:( I'm trully unhappy with this one. Took too much time to figure it out. Just two funny stacks needed.
Subscribe to:
Post Comments (Atom)
Connect Rapoo MT750S with Linux (Tested on Manjaro)
I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...
-
I like coding a lot, keeps me glued to the PC for hours. For that reason it's a need to edit the Syntax Highlighter to suit my eyes for...
-
I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...
-
Method: The problem at first glance seems too straightforward but it's not that much. Think a bit about the lines "Erin can add ...
No comments:
Post a Comment
Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.