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

plz anybody , try to execute this code and enter any test case and tell me where is the trick? why WA?

Posted by hasan83 at 2007-04-08 19:52:33 on Problem 1010
#include<iostream>
using namespace std;

void gene(int p[],int t[],int n,int index,int max,int st[]);
void replace(int p[],int max,int index,int t[]);
void print();

int s[260],ss[260],noof,op[100],onoof,tie,omax,oindex,n,ot[260],*xx;
int main()
{
    int m;
    while(cin>>ss[0])
    {
        m=1;             
        if(ss[0]!=0)
        {             
            for(;cin>>ss[m]&&ss[m]!=0;m++)
            {}
        }
        
        xx=new int[m];
        for(int i=0;i<m;i++)xx[i]=i;             
        for(int i=0;i<=m;i++)s[i]=ss[i];
        for(int i=0;i<m-1;i++)
        {
            for(int j=0;j<m-1;j++)
            {
                if(s[j]>s[j+1])
                {
                   xx[j]=xx[j]+xx[j+1];
                   xx[j+1]=xx[j]-xx[j+1];
                   xx[j]=xx[j]-xx[j+1];                           
                   s[j]=s[j]+s[j+1];
                   s[j+1]=s[j]-s[j+1];
                   s[j]=s[j]-s[j+1];            
                }    
            }    
        }
        for(;cin>>n&&n!=0;)
        {                     
            int *p=new int[100],*t=new int[100],index=0;
            int st[10000]={0},max=0;
            for(int i=0;i<100;i++){p[i]=0;t[i]=0;op[i]=0;ot[i]=0;}
            onoof=0;
            tie=0;
            noof=0; 
            omax=0;  
            oindex=0;            
            gene(p,t,n,index,max,st); 
            print();   
        }
    }
    
    return 0;
}

void gene(int p[],int t[],int n,int index,int max,int st[])
{
     if(n==0)
     {
      /*   for(int j=0;p[j]!=0;j++)cout<<p[j]<<" ";cout<<endl;
         for(int j=0;t[j]!=0;j++)cout<<t[j]<<" ";cout<<endl;
        */ 
         // process //
         if(noof>onoof)
         {
            replace(p,max,index,t);          
         }
         else
         {
             if(noof==onoof)
             {
                 if(index<oindex)
                 {
                     replace(p,max,index,t);            
                 }
                 else
                 {
                     if(index==oindex)
                     {        
                         if(max>omax)
                         {
                             replace(p,max,index,t);                 
                         }
                         else
                         {
                             if(max==omax)
                             {
                                tie++;
                             }
                         }
                     }
                 }           
             }
         }
         return;    
     }
     if(index<4)
     {
         for(int i=0;s[i]!=0&&s[i]<=n;i++)
         {
            if(index==0||(p[index-1]<=s[i]&&t[index-1]<=i+1))
            {
                if(st[i]==0)noof++;
                st[i]++;                                             
                p[index]=s[i];
                t[index]=i+1;
                gene(p,t,n-s[i],index+1,max,st);  
                p[index]=0;
                t[index]=0;
                st[i]--;
                if(st[i]==0)noof--;     
            }     
         }
     }
}

void replace(int p[],int max,int index,int t[])
{
    // cout<<"INDEX = "<<index<<endl;
     tie=0;
     for(int i=0;i<index;i++)
     {
         op[i]=p[i];
         ot[i]=t[i];    
     }     
     omax=max;
     oindex=index;
     onoof=noof;
   //  cout<<"INDEX = "<<index<<endl;
}

void print()
{
     cout<<n<<" ";
     if(tie==0)
     {
        if(onoof==0)
        {
            cout<<"---- none"<<endl;        
        }
        else
        {
            cout<<"("<<onoof<<"): ";
            for(int j=0;j<oindex-1;j++)
            {
                for(int k=0;k<oindex-1;k++)
                {
                    if(xx[ot[k]-1]>xx[ot[k+1]-1])
                    {
                        int temp=ot[k];
                        ot[k]=ot[k+1];
                        ot[k+1]=temp;
                        temp=op[k];
                        op[k]=op[k+1];
                        op[k+1]=temp;
                    }    
                }    
            }
            for(int j=0;j<oindex;j++)
            {
                cout<<op[j]<<" ";    
            }
            cout<<endl;
        }
     }
     else
     {
         cout<<"("<<tie+1<<"): tie"<<endl;
     }
}

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