湖南省大学生计算机程序设计竞赛(残缺的棋盘)
2016-08-05 16:27
155 查看
1511: 残缺的棋盘
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 680 Solved: 244
[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
#include <iostream> #include <stdio.h> #include<queue> #include<string.h> using namespace std; int sx,sy,ex,ey,nx,ny,rr,a[9][9],now[1000][2],nextt[1000][2],nex; int h[8]= {-1,-1,-1,0,0,1,1,1}, l[8]= {-1,0,1,-1,1,-1,0,1}; void bfs(int x,int y) { for(int i=0; i<8; i++) { if(x+h[i]>=1&&x+h[i]<=8&&y+l[i]>=1&& y+l[i]<=8&&a[x+h[i]][y+l[i]]==0) { if(x+h[i]==ex&&y+l[i]==ey) rr=0; a[x+h[i]][y+l[i]]=1; nextt[nex][0]=x+h[i]; nextt[nex++][1]=y+l[i]; } } } int main() { int u=0; while(~scanf("%d%d%d%d%d%d",&sx,&sy,&ex,&ey,&nx,&ny)) { memset(a,0,sizeof(a)); a[nx][ny]=1; int no=1; now[0][0]=sx; now[0][1]=sy; rr=1; int oo=0; while(rr) { nex=0; for(int i=0; i<no; i++) { bfs(now[i][0],now[i][1]); } for(int i=0; i<nex; i++) { now[i][0]=nextt[i][0]; now[i][1]=nextt[i][1]; } oo++; no=nex; } printf("Case %d: %d\n",++u,oo); } return 0; }
相关文章推荐
- 湖南省第十届大学生计算机程序设计竞赛:残缺的棋盘
- 湖南省第十届大学生计算机程序设计竞赛1511: 残缺的棋盘
- 湖南省第十届大学生计算机程序设计竞赛----残缺的棋局
- 多连块拼图(湖南省第七届大学生计算机程序设计竞赛)
- 2017年湖南省第十三届大学生计算机程序设计竞赛赛后总结
- 湖南省第六届大学生计算机程序设计竞赛__弟弟的作业
- 2016年湖南省第十二届大学生计算机程序设计竞赛:G—parathesis
- 湖南省第九届大学生计算机程序设计竞赛 Interesting Calculator
- HNNU 11656 错误的算法【 湖南省第十一届大学生计算机程序设计竞赛,模拟】
- 【贪心】CSU 1809 Parenthesis (2016湖南省第十二届大学生计算机程序设计竞赛)
- 湖南省第八届大学生计算机程序设计竞赛1115: 最短的名字(模拟)
- CSU 1809 Parenthesis【湖南省第十二届大学生计算机程序设计竞赛 G题】
- 湖南省第六届大学生计算机程序设计竞赛 汽水瓶 (小学生题)
- 湖南省第六届大学生计算机程序设计竞赛 E - 台球碰撞
- 2016年湖南省第十二届大学生计算机程序设计竞赛 - G CSU 1809 Parenthesis (线段树)
- 好老师 (湖南省第九届大学生计算机程序设计竞赛)
- 湖南省第十届大学生计算机程序设计竞赛第五题(模拟题)
- CSU 1111 三家人 (湖南省第八届大学生计算机程序设计竞赛 )
- CSU 1115 最短的名字(湖南省第八届大学生计算机程序设计竞赛)
- CSU1810(2016年湖南省第十二届大学生计算机程序设计竞赛 - H)