posts - 100,  comments - 15,  trackbacks - 0
//模拟洗牌,不知道为什么分类是bfs
#include<iostream>
using namespace std;
char s1[101];
char s2[101];
char s12[201];//每次洗牌后的串
char s[201]; //目标串
char first[201];//第一次洗牌后的串
int n,len,len2;
int step;
void shuf()
{
    
int i,j;
    step
=1;
    
while(step)
    
{
        
for(i=0,j=0;i<len;i++)
        
{
            s12[j
++]=s2[i];
            s12[j
++]=s1[i];
        }

        len2
=j;
        
if(step==1) strcpy(first,s12);
        
if(strcmp(s,s12)==0return ;
        
if(step!=1 && strcmp(s12,first)==0{ step=-1;return ;}
        
for(j=0;j<len;j++)
            s1[j]
=s12[j];
        
for(;j<len2;j++)
            s2[j
-len]=s12[j];
        step
++;
    }

}

int main()
{
    
int i,j,k;
    scanf(
"%d",&n);
    
for(k=1;k<=n;k++)
    
{
        memset(s,
0,sizeof(s));
        memset(first,
0,sizeof(first));
        memset(s12,
0,sizeof(s12));
        scanf(
" %d %s %s %s",&len,&s1,&s2,&s);
        shuf();
        
if(step==-1) printf("%d -1\n",k);
        
else printf("%d %d\n",k,step);    
    }

    
return 0;
}
posted on 2009-07-23 15:12 wyiu 阅读(194) 评论(0)  编辑 收藏 引用 所属分类: POJ

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