hdu 1430 魔板
2015-05-17 23:04
435 查看
康拓展开?双向Bfs?
no,no,no,简单单向bfs+map判重就好,不过预处理的思想是不变的。
不过我看了许多博客,也没人解释为何12345678可以达到其他所有的状态
no,no,no,简单单向bfs+map判重就好,不过预处理的思想是不变的。
不过我看了许多博客,也没人解释为何12345678可以达到其他所有的状态
#include<iostream> #include<map> #include<queue> using namespace std; string st,ed; map<string,string>mapp; map<string,string>::iterator it; struct stu { string x; string l; }; string a(string x)//a变换 { string ans=""; for(int i=x.size()-1;i>=0;i--) { ans+=x[i]; } return ans; } string b(string x)//b变换 { string ans=""; ans+=x[3];ans+=x[0];ans+=x[1];ans+=x[2];ans+=x[5];ans+=x[6];ans+=x[7];ans+=x[4]; return ans; } string c(string x)//c变换 { string ans=""; ans+=x[0];ans+=x[6];ans+=x[1];ans+=x[3];ans+=x[4];ans+=x[2];ans+=x[5];ans+=x[7]; return ans; } void bfs()//预处理所有的变换情况 { stu x,y; x.x="12345678"; x.l=""; queue<stu>root; root.push(x); while(root.size()) { x=root.front(); root.pop(); it=mapp.find(x.x); if(it!=mapp.end()) continue; mapp[x.x]=x.l; y.x=a(x.x);y.l=x.l+"A"; root.push(y); y.x=b(x.x);y.l=x.l+"B"; root.push(y); y.x=c(x.x);y.l=x.l+"C"; root.push(y); } } int main() { cin.sync_with_stdio(false); bfs(); while(cin>>st>>ed) { string ans=""; for(int i=0;i<8;i++) { for(int j=0;j<8;j++) { if(ed[i]==st[j]) ans+=(j+'0'+1); } } cout<<mapp[ans]<<endl; } return 0; }
相关文章推荐
- hdu 1430 魔板(bfs+预处理+康托展开)
- HDU - 1430 魔板 (bfs预处理 + 康托)
- hdu 1430 魔板
- HDU 1430 魔板
- hdu 1430 魔板 康托展开 + 很好的映射
- HDU 1430 魔板
- HDU 1430 魔板 搜索
- hdu 1430 魔板
- HDU 1430 魔板 康托展开或字典树 + BFS
- hdu 1430 魔板(bfs+康拓展开)
- [HDU 1430] 魔板
- HDU_1430——魔板,预处理,康托展开,置换,string类的+操作
- HDU 1430 魔板 (BFS)
- HDU-1430 魔板
- HDU 1430 魔板(BFS+HASH+置换)
- HDU-1430 魔板
- HDU 1430 魔板
- HDU 1430 魔板 [BFS+康拓展开]【数学】
- HDU 1430 魔板
- hdu 1430 魔板(康托展开+BFS+巧妙转换)