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 hellgod at 2005-11-24 01:05:54 on Problem 1011
在這邊 judge AC and 0ms , 
but TLE on ACM judge 

can someone tell me why ??

that's my code , thank you!


#include <stdio.h>
#include <stdlib.h>
int cmp(const void * a,const void * b)
{
    return *(int*)b -*(int *)a;
}

int input[1000];

bool record[1000];

bool check(int,int);

bool cut(int len,int i,int n,int count);

int len;

int main()
{
//    freopen("input.txt","r",stdin);
//    freopen("out.h","w",stdout);
    int n,i,sum,k,bound;
    while( EOF != scanf("%d",&n))
    {
         if(n==0) break;
         sum=0;
         for(i=0,k=0;i<n;i++)
         {
            scanf("%d",&input[k]);
            if(input[k]<=50) 
            {
              sum+=input[k];
              record[k]=0;
              k++;
            }
         }
         n=k;
         qsort(input,n,4,cmp);
         bound=sum>>1;
         for(k=input[0]; k<=bound ; k++)
         {
               if(sum %k) continue;
               len=k;
               if(check(sum/k,n))      break;
         }
         
         if(k>bound)printf("%d\n",sum);
         
         else printf("%d\n",len);
    }   
}


bool check(int count,int n)
{
    bool got=true;
    int i=0;
    if(count!=0)
    {
       while(record[i]) i++;
       record[i]=1;
       got=cut(len-input[i],i+1,n,count);
       if(!got) 
           record[i]=0;
    }
    return got;
}

bool cut(int len,int i,int n,int count)
{
    int got=true;
    int k;
    if(len==0) got=check(count-1,n);
    
    else if(i==n) got=false;
    
    else if(!record[i] && input[i]<=len)
    {
        record[i]=1;
        got=cut(len-input[i],i+1,n,count);
        if(!got)
        {
           record[i]=0;
           k=i+1;
           while (input[k]==input[i] &&  k < n) k++;
           
           if(k<n) got=cut(len,k,n,count);

           else got=false;
        }
    }
    
    else  
    {
         k=i+1;
         while(record[k] || input[k]>len) k++;
         if(k<n) got=cut(len,k,n,count);

           else got=false;
    }
    return got;
} 

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