topcoder,the third time...

topcoder,the third time...

n用了10000测试,最后改成50000忘了编译。。。结果... 哈哈 tc第一次教训。。。

#include < iostream >
#include
< vector >
using   namespace  std;

int  n,m;
int  len;

int   get (vector  < int >  A)
{

    len
=A.size();
    
int sum=0;
    
int i;
    
for(i=0;i<n;i++)
        sum
+=A[len-1-i];
    sum
%=10;
    
return sum;
}


bool  check(vector  < int >  A, vector  < int >  B)
{

    
int k;
    
int alen=A.size();
    
int blen=B.size();
    
for(k=0;k<m;k++)
    
{

        
if(A[alen-1-k]!=B[blen-1-k])
            
return false;
    }

    
return true;
}

bool  check(vector  < int >  A, vector  < int >  B, int  i)
{

    
int k;
    
int alen=A.size();
    
int blen=B.size();
    
for(k=0;k<m;k++)
    
{

        
if(A[i+k]!=B[k])
            
return false;
    }

    
return true;
}


class  EasySequence
{

public:
    
int find(vector <int> A, vector <int> B)
    
{
        n
=A.size();//n是原始的长度
        m=B.size();
        
int alen=n;
        
int blen=m;
        
while(alen<blen)
        
{

            A.push_back(
get(A));
            alen
++;
        }


        
int i;
        
for(i=0;i<n-m;i++)
        
{
            
if(check(A,B,i))
                
return i;
        }

    
        
int cnt=0;
        
while(true)
        
{
            
if( check(A, B) )
            
{

                
return alen-m;
            }

            
else
            
{
                A.push_back(
get(A));
                alen
++;
            }

            
if(cnt>=50000)
                
                
return -1;
            
else
                cnt
++;
        }




    }

}
;


int  main()
{

    vector
<int>A;
    vector
<int>B;
    A.push_back(
1);
    A.push_back(
2);
    A.push_back(
3);
    A.push_back(
4);
    A.push_back(
5);
    B.push_back(
4);
    B.push_back(
5);
    EasySequence t;
    
int res=t.find(A,B);


}


 

你可能感兴趣的:(topcoder,the third time...)