跳棋

一维跳棋(BFS)

落爺英雄遲暮 提交于 2020-01-14 00:41:12
一维跳棋是一种在1×(2N+1) 的棋盘上玩的游戏。一共有N个棋子,其中N 个是黑的,N 个是白的。游戏开始前,N 个白棋子被放在一头,N 个黑棋子被放在另一头,中间的格子空着。 在这个游戏里有两种移动方法是允许的:你可以把一个棋子移到与它相邻的空格;你可以把一个棋子跳过一个(仅一个)与它不同色的棋子到达空格。 对于N=3 的情况,棋盘状态依次为: 1 WWW BBB 2 WW WBBB 3 WWBW BB 4 WWBWB B 5 WWB BWB 6 W BWBWB 7 WBWBWB 8 BW WBWB 9 BWBW WB 10 BWBWBW 11 BWBWB W 12 BWB BWW 13 B BWBWW 14 BB WBWW 15 BBBW WW 16 BBB WWW 对应的空格所在的位置(从左数)为:3 5 6 4 2 1 3 5 7 6 4 2 3 5 4。 输入格式 输入仅一个整数,表示针对N(1≤N≤10) 的取值。 输出格式 依次输出空格所在棋盘的位置,每个整数间用空格分隔,每行5 个数(每行结尾无空格,最后一行可以不满5 个数;如果有多组移动步数最小的解,输出第一个数最小的解) 样例输入 4 样例输出 4 6 7 5 3 2 4 6 8 9 7 5 3 1 2 4 6 8 7 5 3 4 6 5 用二进制来表示棋盘的状态 1 #include <stdio.h> 2

P3024 [USACO11OPEN]奶牛跳棋Cow Checkers

眉间皱痕 提交于 2019-12-03 21:12:07
题目描述 One day, Bessie decides to challenge Farmer John to a game of 'Cow Checkers'. The game is played on an M*N (1 <= M <= 1,000,000; 1 <= N <= 1,000,000) checkerboard that initially contains a single checker piece on the checkboard square coordinates (X, Y) (0 <= X < M; 0 <= Y < N). The bottom leftmost square of the checkerboard has coordinates (0, 0), and the top rightmost square has coordinates (M-1, N-1). Bessie always moves first, and then the two players alternate turns. Each turn comprises one of three types of moves: Move the checker piece to any square on the same row to the left of