The Fourth Dimension Space

枯叶北风寒,忽然年以残,念往昔,语默心酸。二十光阴无一物,韶光贱,寐难安; 不畏形影单,道途阻且慢,哪曲折,如渡飞湍。斩浪劈波酬壮志,同把酒,共言欢! -如梦令

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);


}


 

posted on 2009-12-18 02:29 abilitytao 阅读(988) 评论(2)  编辑 收藏 引用

评论

# re: topcoder,the third time... 2009-12-18 15:46 陈梓瀚(vczh)

函数参数要么vector<int>&,要么const vector<int>&,用vector<int>是不对的。  回复  更多评论   

# re: topcoder,the third time...[未登录] 2009-12-19 18:15 abilitytao

@陈梓瀚(vczh)
这里并不需要保护呀  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理