HDU 1043、POJ 1077
来源:互联网 发布:陈丹梅 淘宝店 编辑:程序博客网 时间:2024/05/16 00:31
在HDU无压力过,在POJTLE。。。。
#include <iostream>#include <stack>#include <queue>#include <vector>using namespace std;int vis[1000000];int dir[1000000][2];queue< vector<short> > q;queue<int> zt; int start;int target;const int dx[] = {-1, 1, 0 ,0};const int dy[] = {0, 0, -1, 1};int fac[9] = {0, 1, 2, 6, 24, 120, 720, 5040, 40320 };int kt(vector<short> &temp){int re = 1;int hash[9] = {0,0,0,0,0,0,0,0,0};for(int i = 0; i < 8; i++){hash[temp[i]] = 1;int number = 0;for(int j = temp[i]-1; j >= 0; j--)if(!hash[j])number++;re += fac[8-i]*number;}return re;}int main(){char temp, counter = 0;vector<short> vtemp;vtemp.push_back(1);vtemp.push_back(2);vtemp.push_back(3);vtemp.push_back(4);vtemp.push_back(5);vtemp.push_back(6);vtemp.push_back(7);vtemp.push_back(8);vtemp.push_back(0);zt.push(kt(vtemp));vis[zt.front()] = 1;target = zt.front();q.push(vtemp);while(!q.empty()){vector<short> rear = q.front();q.pop();int r = zt.front();zt.pop();int z;for(z = 0; z < 9; z++)if(!rear[z])break;int x = z/3, y = z%3;int newx, newy, newz;for(int i = 0; i < 4; i++){newx = x + dx[i];newy = y + dy[i];newz = newx*3 + newy;if(newx >= 0 && newx < 3 && newy >= 0 && newy < 3){vector<short> newv(rear);int temp = newv[z];newv[z] = newv[newz];newv[newz] = temp; int newr = kt(newv); if(!vis[newr]){ vis[newr] = 1; zt.push(newr); dir[newr][0] = r; dir[newr][1] = i; q.push(newv);}}}}while(cin >> temp){vector<short>vtemp;vtemp.push_back(temp == 'x' ? 0 : temp - '0');for(int i = 1; i < 9; i++){cin >> temp; if(temp >= '1' && temp <= '8'){vtemp.push_back(temp-'0');}elsevtemp.push_back(0);}start = kt(vtemp);bool isanswer = false;if(vis[start])isanswer = true;if(isanswer){int now = start;stack<char> out;while(now != target){switch(dir[now][1]){case 0: cout << "d"; break;case 1: cout << "u"; break;case 2: cout << "r"; break;case 3: cout << "l";}now = dir[now][0];}while(!out.empty()){cout << out.top();out.pop();}cout << endl;}else{cout << "unsolvable" << endl;}}return 0;}
- HDU 1043、POJ 1077
- HDU 1043 ,POJ 1077 Eight
- poj 1077-Eight;hdu 1043-Eight
- POJ 1077 HDU 1043 Eight (IDA*)
- poj 1077 + HOJ 10466 + hdu 1043 eight
- 八数码A*【POJ-1077 HDU-1043】
- HDU 1043 && POJ 1077 Eight (A*)
- poj 1077 hdu 1043 八数码
- bfs+hash poj 1077/hdu 1043 八数码问题
- poj 1077 zoj 1217 hdu 1043 八数码
- hdu 1043 poj 1077 Eight Time (搜索&八数码)
- HDU 1043 / POJ 1077 Eight(八数码问题)
- HDU 1043 Eight poj 1077 (八数码 启发式搜索)
- POJ 1077(HDU 1043)Eight(八数码DBFS)
- 八数码(POJ-1077或HDU-1043)
- HDU 1043 && POJ 1077 Eight bfs || 双向bfs || A*搜索
- poj 1077 & hdu 1043 Eight ( 多种解法:预处理、bfs、dbfs、IDA*、A*)
- HDU 1043 Eight(经典八数码问题)对比POJ 1077(bfs)
- 启动错误:emulator-5554 disconnected
- 菜鸟的时间轴
- 再看Vector容器
- error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To di
- xStream完美转换XML、JSON
- HDU 1043、POJ 1077
- 谷歌用户体验设计准则
- 2012年写给移动互联网朋友创业项目建议(草拟)
- Windows 7 安装软件错误:“Error 1935 ...HRESULT: 0x800736FD” 的解决办法
- CV牛人牛事简介
- GPS/BD1定位数据转换
- 那缕清香,右手阑珊,左手寂寞
- 那缕清香,右手阑珊,左手寂寞
- FUCK电信