POJ 1077
下面的代码总是TLE。。。
1. 使用STL set
for(int i = 0; i < 4; i++)
{
S *ns = getState(ps, i);
if(ns && (hash.find(*ns) == hash.end()))
{
//print(*ns);
hash.insert(*ns);
q.push(ns);
}
}
}
}
int main()
{
char c[9];
for(int i = 0; i < 9; i++)
{
//cin >> c[i];
scanf("%c ", &(c[i]));
}
S s(c, 0, 0);
hash.insert(s);
//cout << (*hash.find(s1)).op << endl;
//cout << (hash.find(s1) != hash.end()) << endl;
q.push(&s);
BFS();
}
2. 使用hash
for(int i = 0; i < 4; i++)
{
S *ns = getState(ps, i);
if(ns)
{
if(try_to_insert(ns))
{
q.push(ns);
}
}
}
}
}
int main()
{
char c[9];
for(int i = 0; i < 9; i++)
{
scanf("%c ", &(c[i]));
if(c[i] == 'x')
{
c[i] = '0';
}
}
S s(c, 0, 0);
st[sno++] = &s;
q.push(&s);
BFS();
}
测试结果:
注:网上的一个hash的ac代码