| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
数据都过了,但是为什么就是WA啊。求大神教教小弟。十分感谢啊。以下附代码。#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
string s1,s2,c;
int n,m;
struct node
{
string cc;
int t;
};
int bfs()
{
queue<node> p;
while(!p.empty()) p.pop();
node q;
for(int i=0;i<m;i++)
{
q.cc+=s2[i];
q.cc+=s1[i];
}
q.t=1;
p.push(q);
while(!p.empty())
{
if(p.front().cc==c)
return p.front().t;
for(int i=0;i<m;i++)
s2[i]=p.front().cc[i];
for(int i=m,j=0;i<2*m;i++,j++)
s1[j]=p.front().cc[i];
node pp;
for(int i=0;i<m;i++)
{
pp.cc+=s2[i];
pp.cc+=s1[i];
}
pp.t=p.front().t+1;
p.push(pp);
p.pop();
if(p.front().cc==q.cc)
return -1;
}
return -1;
}
int main()
{
int num,num1=1;
cin>>n;
while(n--)
{
cin>>m;
s1="\0";
s2="\0";
c="\0";
cin>>s1>>s2>>c;
num=bfs();
cout<<num1<<" "<<num<<endl;
num1++;
}
return 0;
}
求大神帮忙啊。小弟十分感谢啊。
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator