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

TLE 不知道原因,按照我的思路,我这样应该是不会超时的

Posted by fyhue at 2007-08-08 12:18:09 on Problem 3320
#include <stdio.h>
unsigned long int a[1000000], b[1000000], c[1000000];
int main()
{
    unsigned long int p, i, m, j, count=0, flag;
    while(scanf("%d",&p)==1)
    {
        count=0;
        if(p==0)
        {
            printf("0\n");
            continue;
        }
        for(i=0; i<p; i++)
        {
            scanf("%d",&a[i]);
            if(count)
            {
                flag=1;
                for(j=0; j<count; j++)
                {
                    if(b[j]==a[i])
                    {
                        flag=0;
                        while(j<count-1)
                        {
                            b[j]=b[j+1];
                            c[j]=c[j+1];
                            j++;
                        }
                        b[j]=a[i];
                        c[j]=i;
                        if(m>(i+1-c[0]))
                        {
                            m=i+1-c[0];
                        }
                        break;
                    }
                }
                if(flag)
                {
                    b[j]=a[i];
                    count++;
                    c[j]=i;
                    m=i+1-c[0];
                }
            }
            else
            {
                b[0]=a[i];
                count++;
                c[0]=i;
                m=1;
            }
        }
        if(count==1)
        {
            printf("1\n");
            continue;
        }
        if(count==p)
        {
            printf("%d\n",p);
            continue;
        }
        printf("%d\n", m);
    }
    return 0;
}

我的一直是TLE,但是,不知道哪里慢下来的,请大家帮忙指点。

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