uva439 暂时未AC代码
来源:互联网 发布:知行乐学教育集团 编辑:程序博客网 时间:2024/05/17 03:56
#include <iostream>#include <cstdio>#include <queue>#include <string.h>using namespace std;struct Node{ int x; int y; int step;};Node vs;Node vd;char ch;int m;char ch1;int m1;int ans;queue <Node> q;bool visit[10][10];int dir[8][2]= {-1,-2,-1,2,-2,-1,-2,1,1,2,1,-2,2,1,2,-1};void initial(){ ans=0; memset(visit,0,sizeof(visit)); vs.x=m; vs.y=ch-'a'; vs.step=0; vd.x=m1; vd.y=ch1-'a'; vd.step=0; while(!q.empty()) q.pop();}void bfs(){ Node vn,vw; q.push(vs); visit[vs.x][vs.y]=true; while(!q.empty()) { vn=q.front(); q.pop(); for(int j=0; j<8; j++) { vw.step=vn.step+1; vw.x=vn.x+dir[j][0]; vw.y=vn.y+dir[j][1]; if(vw.x==vd.x && vw.y==vd.y) { ans=vw.step; return ; } if(!visit[vw.x][vw.y] && (vw.x>0 && vw.x<=8 && vw.y>0 && vw.y<=8)) { q.push(vw); visit[vw.x][vw.y]=true; } } } return ;}int main(){ while(~scanf(" %c%d %c%d",&ch,&m,&ch1,&m1)) { initial(); bfs(); if(ch==ch1 && m==m1) { printf("To get from %c%d to %c%d takes 0 knight moves.\n",ch,m,ch1,m1); } else { printf("To get from %c%d to %c%d takes %d knight moves.\n",ch,m,ch1,m1,ans); } } return 0;}
测试了很多组数据 都对……但是就是没有AC……留作以后再改
阅读全文
0 0
- uva439 暂时未AC代码
- UVA439
- uva439
- UVA439
- uva439
- uva439
- 暂时未写博客
- 未AC
- 暂时保存代码
- [未AC]HDU1002
- HDU4069(未AC)
- UVa1589(未ac)
- 未AC 题
- uva10142(未ac)
- uva336(未ac)
- AC代码
- 福州oj 1689 未ac
- HDU 5035(未AC)
- 自我学习心得JavaEE
- 获取系统时间
- Java中生成excel,并进行数据的写入读出
- 读书笔记 TCP/IP详解 卷1
- 设计模式介绍
- uva439 暂时未AC代码
- poj2723 Get Luffy Out (二分+2-SAT)
- Jsp---JSTL
- 归并排序
- 区间之和
- 如何建立DLL
- 操作符小结
- bzoj3402 [Usaco2009 Open]Hide and Seek 捉迷藏
- 这六段代码隐藏着深度学习的前世今生!