| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
这题思路很简单,出栈为n,则栈顶必为小于n并且尚未出栈中最大的,如果出栈数小于栈顶,No。但是我的代码63ms,求大牛降复杂度#include<stdio.h>
#include<memory.h>
#define MAX 1001
int hash[MAX];
int main()
{
int n,c,i,j,top,sign;
while(scanf("%d",&n),n)
{
while(scanf("%d",&c),c)
{
sign=0;
memset(hash,0,sizeof(hash));
top=c-1;
hash[c]=1;
for(i=0;i<n-1;i++)
{
scanf("%d",&c);
if(sign) continue;
if(c<top)
{
sign=1;
printf("No\n");
}
else
{
hash[c]=1;
for(j=c-1;j>=1;j--)
{
if(!hash[j])
{
top=j;
break;
}
}
}
}
if(!sign) printf("Yes\n");
}
printf("\n");
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator