C++的在Linux不能过?

大家帮忙看看我的代码,在windows和RQ下秒过,但是交到Vijos上就对了一组了。。。。

难道是set的问题???

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
#include<queue>
#include<set>
using namespace std;

string start,end;
string a[10],b[10];
int n;
set<string> hash;
struct node{string s;int step;};
queue<node> q;

void work(node tt,int k)
{
string s=tt.s;
int pos=0;
string tmp=s;
while(1)
{
//find all positions
int p=tmp.find(a[k]);
pos+=p+1;
tmp.erase(0,p+1);
if((int)p==-1) break;
//printf("%d ",pos);
//cout<<s<<endl;
//-----end
//change
pos--;
node res;res.s="";res.step=tt.step+1;
for(int i=0;i<pos;i++) res.s+=s[i];
res.s+=b[k];
for(int i=pos+a[k].length();i<s.length();i++) res.s+=s[i];
//cout<<res.s<<endl;
pos++;
//-----end
if(res.s==end)
{
printf("%d\n",res.step);
exit(0);
}
if(res.step==11) continue;
if(!hash.count(res.s))
{
hash.insert(res.s);
q.push(res);
}
}
}

int main()
{
//freopen("noipg2.in","r",stdin);
//freopen("noipg2.out","w",stdout);
cin>>start>>end;
if(start==end) {printf("0");exit(0);}
while(cin>>a[++n]>>b[n]);n--;
node sta;sta.s=start;sta.step=0;
q.push(sta);
while(!q.empty())
{
node t=q.front();q.pop();
for(int i=1;i<=n;i++)
{
work(t,i);
}
}
printf("NO ANSWER!");
return 0;
}

1 条评论

  • @ 2013-03-24 17:09:44

    Vijos评测机目前为windows

  • 1

信息

ID
1124
难度
7
分类
搜索 | 搜索与剪枝 点击显示
标签
递交数
3886
已通过
784
通过率
20%
被复制
14
上传者