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

枚举 不过超时 汗!!!!

Posted by sdau_085111 at 2010-11-24 15:58:39 on Problem 2244 and last updated at 2011-01-27 16:21:43
#include<stdio.h>
#define bool _Bool
#define true 1
#define false 0

int n;
bool have[150];
bool last;

int main()
{
    int i;
    while(scanf("%d",&n)&&n!=0)
    {
        for(i=2;;i++)
        {
            memset(have,0,sizeof(have));
            last=false;


///本来是next()函数,由于超时,所以拿出来,不过还是TLE!!!,有空再看
            int _i,c=1,_j,cnt=0;
            int _cnt=0;
            have[c]=true;
            //printf("%d\n",c);
            _cnt++;
            for(_i=0;_i<n;_i++)
            {
                for(_j=0;_j<i;_j++)
                {
                    while(have[(c+1)%n]==true)
                    {
                        c=(c+1)%n;
                        cnt++;
                        if(cnt>n) goto nextstep;
                    }
                    cnt=0;
                    c=(c+1)%n;
                    }
                    have[c]=true;
                    if(c==0) c+=n;
                    //printf("%d\n",c);
                    _cnt++;
                    if(_cnt==n&&c==2) last=true;
            }
////////////////


    nextstep:if(last==true)
            {
                printf("%d\n",i);
                break;
            }
        }
    }
    return 0;
}
只好打表!

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