| ||||||||||
| 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 | |||||||||
我的算法已经O(n)了,为什么还刷不到0ms,还有什么改进地方吗#include "stdio.h"
int main(void)
{
int a[1010]={0},n,i,x,flag,min,now,temp;
while(scanf("%d",&n)==1&&n)
{
while( scanf("%d",&x)==1&&x)
{
flag=1;
for(i=1;i<=n;a[i++]=0);
a[x]=1,min=x,now=x; //now表示现在停在哪个数,下个读入的数要么是now-1要么比now大
for(i=2;i<=n;i++)
{
scanf("%d",&x);
a[x]=1;
if(flag==1)
{
if(x>now) now=x;
else if(x!=now-1) flag=0;
else { now--; if(a[min-1]) min--;}
if(a[now-1]) now=min;
}
}
if(flag) printf("Yes\n");
else printf("No\n");
}
printf("\n");
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator