http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511
1511: 残缺的棋盘
时间限制: 1 Sec 内存限制: 128 MB题目描述
输入
输入包含不超过10000 组数据。每组数据包含6个整数r1, c1, r2, c2, r3, c3 (1<=r1, c1, r2, c2, r3, c3<=8). 三个格子A, B, C保证各不相同。
输出
对于每组数据,输出测试点编号和最少步数。
样例输入
1 1 8 7 5 6
1 1 3 3 2 2
样例输出
Case 1: 7
Case 2: 3
提示
来源
分析:
8 x 8 的棋盘,BFS搜索可以解决,一开始队友写错了条件导致TLE , 后来又写了一个笛卡尔坐标模拟的,但是pc^2判错啦 , 后来在csuoj上提交也是错的,对照数据没有发现错误,真是无语啦,把其他队的AC代码提交到csuoj上也是WA,真是服了,但是搜索做的都过啦,,,orz
AC代码:
1 #include<iostream> 2 #include<stdio.h> 3 #include<cmath> 4 #include<algorithm> 5 #include<stack> 6 #include<queue> 7 #include<map> 8 #include<set> 9 #include<string.h> 10 #define ll long long 11 #define oo 1000007 12 #define pi acos(-1.0) 13 #define MAXN 500005 14 using namespace std; 15 struct node 16 { 17 int x,y,k; 18 }h,p; 19 int m,n,k,ex,ey,num[105][105][1005]; 20 bool used[105][105][1005]; 21 queue<node> myqueue; 22 int main() 23 { 24 while (~scanf("%d%d%d%d%d%d%d",&n,&m,&h.x,&h.y,&ex,&ey,&k)) 25 { 26 while (!myqueue.empty()) myqueue.pop(); 27 h.k=0; 28 myqueue.push(h); 29 memset(num,0,sizeof(num)); 30 memset(used,false,sizeof(used)); 31 used[h.y][h.x][0]=true; 32 num[h.y][h.x][0]=1; 33 while (!myqueue.empty()) 34 { 35 h=myqueue.front(); 36 myqueue.pop(); 37 if (h.k==k) continue; 38 if (h.y+1<=m) 39 { 40 p.x=h.x,p.y=h.y+1,p.k=h.k+1; 41 if (!used[p.y][p.x][p.k]) myqueue.push(p),used[p.y][p.x][p.k]=true; 42 num[p.y][p.x][p.k]=(num[p.y][p.x][p.k]+num[h.y][h.x][h.k])%oo; 43 } 44 if (h.x-1>=1) 45 { 46 p.x=h.x-1,p.y=h.y,p.k=h.k+1; 47 if (!used[p.y][p.x][p.k]) myqueue.push(p),used[p.y][p.x][p.k]=true; 48 num[p.y][p.x][p.k]=(num[p.y][p.x][p.k]+num[h.y][h.x][h.k])%oo; 49 } 50 if (h.x+1<=n) 51 { 52 p.x=h.x+1,p.y=h.y,p.k=h.k+1; 53 if (!used[p.y][p.x][p.k]) myqueue.push(p),used[p.y][p.x][p.k]=true; 54 num[p.y][p.x][p.k]=(num[p.y][p.x][p.k]+num[h.y][h.x][h.k])%oo; 55 } 56 } 57 printf("%d\n",num[ey][ex][k]); 58 } 59 return 0; 60 }