zoj2097-Walking on a Chessboard
来源:互联网 发布:手绘是什么软件 编辑:程序博客网 时间:2024/04/30 06:24
有点郁闷,我就像怎么老是wa,看了别人的代码才发现原来那个状态是这个意思,最可恶的就是cost一个要按照累计值,一个只是计算值= =题目一点都没有区别开来
#include<iostream>#include<algorithm>#include<memory.h>#include<queue>using namespace std;struct point{int x,y;int state;int val;}start, temp, other;int n1,n2,m1,m2;int num[8][8];int status[8][8][5];int direction[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};int cost;void BFS(){queue<point> que;start.x = n1;start.y = n2;start.state = 1;start.val = 0;que.push(start);while (!que.empty()){temp = que.front();que.pop();if( temp.x == m1 && temp.y == m2) {if(temp.val < cost)cost = temp.val;}for(int i=0; i<4; i++){int x = temp.x + direction[i][0];int y = temp.y + direction[i][1];if( x>0 && x<=8 && y>0 && y<=8 ){other.x = x;other.y = y;other.val = temp.val + temp.state * num[x-1][y-1];other.state = (temp.state * num[x-1][y-1]) % 4 + 1;if( status[x-1][y-1][other.state] == 0 || other.val < status[x-1][y-1][other.state] ){status[x-1][y-1][other.state] = other.val;que.push(other);}}}}}int main(){while( cin>>n1>>n2>>m1>>m2 && n1!=0 && n2!=0 && m1!=0 && m2!=0 ){for( int i=0; i<8; i++)for( int j=0; j<8; j++)cin>>num[i][j];memset(status, 0, sizeof(status));cost = (1 << 30);BFS();cout<<cost<<endl;}return 0;}
- zoj2097-Walking on a Chessboard
- zoj 2097 Walking on a Chessboard
- zoj 2097 Walking on a Chessboard
- CSUOJ 1302 - Walking on Chessboard 暴力BFS
- zju 2097 Walking on a Chessboard(二维BFS+一维状态转移)
- UVA10161Ant on a Chessboard
- Ant on a Chessboard
- Ant on a Chessboard
- Ant on a Chessboard
- Ant on a Chessboard
- UVA10161Ant on a Chessboard
- 10913 - Walking on a Grid
- 10913 - Walking on a Grid
- UVA10913 - Walking on a Grid
- Walking on a Grid uva10913
- 10161 - Ant on a Chessboard
- uva10161 Ant on a Chessboard
- UVA10161 Ant on a Chessboard
- poj1477
- Cocos2D-X SimpleGame & 初学者教程
- static函数与普通函数
- BOOL和bool的区别
- 系统没有远程桌面,如何安装远程桌面
- zoj2097-Walking on a Chessboard
- Eclipse热键
- WEB-上传文件
- Ubuntu上搭建SVN服务器全攻略
- Java之美[从菜鸟到高手演变]之智力题
- java中float/double浮点数的计算失去精度问题(即小数位数增加的问题)
- 使用excel数据初始javabean
- 一种类似快速排序的移动算法
- 跑马灯效果影响EditText的焦点