Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我的算法已经O(n)了,为什么还刷不到0ms,还有什么改进地方吗

Posted by zerocool_08 at 2005-11-05 23:09:36 on Problem 1363
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator