ACM--BFS--残缺的棋盘--CUS 1511--第十届湖南省赛
来源:互联网 发布:天盾android数据恢复 编辑:程序博客网 时间:2024/05/22 15:09
1511: 残缺的棋盘
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 169 Solved: 56
[Submit][Status][Web Board]Description]
Input
输入包含不超过10000 组数据。每组数据包含6个整数r1, c1, r2, c2, r3, c3 (1<=r1, c1, r2, c2, r3, c3<=8). 三个格子A, B, C保证各不相同。
Output
对于每组数据,输出测试点编号和最少步数。
Sample Input
1 1 8 7 5 6
1 1 3 3 2 2
Sample Output
Case 1: 7
Case 2: 3
================================华丽的分割线===========================
这个是湖南省第十届省赛的一道简单的搜索题目,直接BFS就可以求出来。但是写的时候要注意一些细节
#include <stdio.h>#include <queue>#include <algorithm>#include <string.h>#include <stdlib.h>using namespace std;int visited[205][205];int move[8][2]={{1,0},{-1,0},{0,1},{0,-1},{1,-1},{1,1},{-1,1},{-1,-1}};//周围的八个方向跳int result_x,result_y,ob_x,ob_y;struct node{ int x,y; int step;};//用来判断位置是否合法bool check(int x,int y){ if(x>8||y>8||x<1||y<1) return true; if(x==ob_x&&y==ob_y) return true; if(visited[x][y]) return true; return false;}int bfs(int x,int y){ int i; queue<node> q; node temp,newNode; temp.x=x; temp.y=y; temp.step=0; q.push(temp); while(!q.empty()){ temp=q.front(); q.pop(); //返回步数 if(temp.x==result_x&&temp.y==result_y) return temp.step; for(i=0;i<8;i++){ newNode.x=temp.x+move[i][0]; newNode.y=temp.y+move[i][1]; if(check(newNode.x,newNode.y)) continue; newNode.step=temp.step+1; visited[newNode.x][newNode.y]=1; q.push(newNode); } }}int main(){ int x,y; int index=1; while(~scanf("%d%d%d%d%d%d",&x,&y,&result_x,&result_y,&ob_x,&ob_y)){ memset(visited,0,sizeof(visited)); visited[x][y]=1; int sum=bfs(x,y); printf("Case %d: ",index); index++; printf("%d\n",sum); }return 0;}
参考博客:http://blog.csdn.net/whjkm/article/details/44986067
http://blog.csdn.net/u012860063/article/details/41777745
- ACM--BFS--残缺的棋盘--CUS 1511--第十届湖南省赛
- 湖南省第十届大学生计算机程序设计竞赛:残缺的棋盘
- CSUOJ 1511 残缺的棋盘(BFS)
- 湖南省第十届大学生计算机程序设计竞赛----残缺的棋局
- CSU 残缺的棋盘 (BFS)
- CSU 1511: 残缺的棋盘(BFS啊 )
- 湖南省大学生计算机程序设计竞赛(残缺的棋盘)
- CSU1511-残缺的棋盘-模拟/BFS
- CSU 1511 残缺的棋盘
- 1511: 残缺的棋盘 coj
- CSU 1511 残缺的棋盘
- CSU 1511 残缺的棋盘
- COJ 1511:残缺的棋盘
- CSUOJ-1511: 残缺的棋盘
- csu1511——残缺的棋盘(bfs)
- CSU-1511 残缺的棋盘 解题报告
- CSU 1511——残缺的棋盘
- CSU_1511_残缺的棋盘
- header函数运用
- annovar对人类基因组和非人类基因组variants注释流程
- Css背景
- Docker--容器中数据管理--RHEL7.2
- iOS、mac开源项目及库汇总
- ACM--BFS--残缺的棋盘--CUS 1511--第十届湖南省赛
- JSch:纯JAVA实现SFTP文件上传和下载
- hadoop经典wordcount和hdfs增加删除追加
- HTML5 video标签播放本地视频只有声音没有图像 解决办法
- .ashx接收APPCAN发送过来的图片数据流,保存为图片
- Android 加载外部so
- nodejs 模板 ejs helloworld
- iOS 开发工具集合
- 检查request返回值类型的一个小方法