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

怎么会有Runtime Error?

Posted by zippo at 2005-11-25 12:29:38 on Problem 1011
请大虾帮忙,我去eva找了一些测试数据,都没有问题。自己也检查了几遍,每次都是RE,郁闷!
#include <iostream>
using namespace std;

const int MAXNUM=100;

const int MAX=50;

short pieces[MAXNUM];
short boxes[MAXNUM];
short distinctBox[MAXNUM];
short valueBox[MAXNUM];
int total=0,boxCount=0;
short testnumber=0;

short forbidden[MAXNUM+1][MAXNUM];
short forbidCount[MAXNUM+1]={0};
short values=0;
short disValueCount=1;
short disValue[MAXNUM];

int debug=0;


void sort(short data[],int number)
{
    short tmp=0;
	for(int i=0;i<number;++i)
	{
	  for(int j=i;j<number;++j)
	  {
       	  if(data[i]<data[j])
		  {
		    tmp=data[i];
		    data[i]=data[j];
            data[j]=tmp; 
		  }
	  }
	}
   
  for(i=1;i<number;++i)
    if(data[i]!=data[i-1])
	{
	   ++disValueCount;
	   disValue[disValueCount]=data[i];
	} 
}

int getValue(short vv)
{
  for(int i=1;i<disValueCount;++i)
  {
    if(disValue[disValueCount]==vv)
		return i;
  }
}

bool check (int start)
{
   
   int j,i;
   
   if(start==total)
	   return true;

   short last=0;
   short tmp;

    for(j=0;j<boxCount;++j)
	{
	   for(i=0;i<last;++i)
         if(valueBox[i]==boxes[j])
			 break;
       if(i==last)
	   {
		 distinctBox[last]=j;
		 valueBox[i]=boxes[j];
		   ++last;
	   }
	}
    
   for(j=0;j<last;++j)
	  {
	     tmp=distinctBox[j];  
         
	  	 if(start>0)
		   if(pieces[start]==pieces[start-1])
	  	   {
              
		      values=getValue(pieces[start]); 
			  for(int z=0;z<forbidCount[values];++z)
			  {
				  if(forbidden[values][z]==boxes[tmp])
					  break;
			  }
              if(z<forbidCount[values])
				  continue;
		   }

	     if( (boxes[tmp]+pieces[start]) <= testnumber )
		 {
			 
		     boxes[tmp]=boxes[tmp]+pieces[start];
  
			 			 
		     if(check(start+1)==false)
			 {
				 boxes[tmp]=boxes[tmp]-pieces[start];
				 values=getValue(pieces[start]);
                 debug=forbidCount[values];
                 forbidden[values][debug]=boxes[tmp];
				 ++(forbidCount[values]);
			 }
			 else return true;
		}
      }
	   
   return false;
}


int main(int argc, char* argv[])
{
    
    int   results[300]={0};

	int i;
	
	int sum,biggest;

	cin>>total;

	int count=0;

	while(total!=0)
	{
      sum=0;
	  biggest=1;
      count=0;

      for( i=0;i<total;++i)
	  {
	    cin>>pieces[count];
		if((pieces[count]>MAX)||(pieces[count]<=0))
			continue;
		sum=sum+pieces[count];
		
		if(pieces[count]>biggest)
			biggest=pieces[count];

		++count;
	  }
      
      total=count;

      sort(pieces,total);
    

	  for(i=biggest;i<=sum;++i)
	  {
	    if(sum%i!=0)
			 continue;

		boxCount=sum/i;
		for(int m=0;m<boxCount;++m) 
			boxes[m]=0;
        
        testnumber=i;
		
		values=1;
		for(int mm=1;mm<=MAXNUM;++mm)
			forbidCount[mm]=0;

        if(check(0))
		{
          ++results[0];
		  results[results[0]]=i;
		  break;
		}
	  }
	  

      cin>>total; 
	}

	for(int j=1;j<=results[0];++j)
		cout<<results[j]<<endl;
   
	   //cin>>total; 
	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