ACM--BFS--残缺的棋盘--CUS 1511--第十届湖南省赛
2016-04-27 16:42
471 查看
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就可以求出来。但是写的时候要注意一些细节
参考博客:http://blog.csdn.net/whjkm/article/details/44986067
http://blog.csdn.net/u012860063/article/details/41777745
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
相关文章推荐
- jsoup解析文档
- 【转】SQL*Loader 详解
- Redis Sentinel集群方案--单机测试
- java常用英语单词
- 实现不同概率抽奖功能
- 第八周项目1—数组做数据成员(多文件)
- Activity 里面点击弹出Dialog ,第二次进入点击崩溃!
- 华丽丽的GridLayout-使用案例
- Java常见问题-JRE版本
- koa-send 实现下载文件
- MySQL子查询与连接
- Android酷炫实用的开源框架(UI框架)
- MS三轮面试总结
- 动态创建style片段和script片段
- frame和bounds的区别&&关于CGRect包含交错,边缘,中心的检测
- 图的最小生成树
- Build.gradle详细配置说明
- 个人冲刺02
- 在线制作安卓手机主题
- [netty] netty socket.io的安装测试