【暴力枚举&BFS】Flow Free @RMRC2017/upcexam5124

本文介绍了解决Flow Free 4x4谜题的策略,包括暴力枚举每个空白格子的颜色,并使用宽度优先搜索(BFS)从起点搜索终点,确保所有相同颜色的终点都被路径连接。题目描述了谜题规则,要求确定给定的4x4谜题是否可解。样例输入和输出展示了问题的实例。
摘要由CSDN通过智能技术生成

时间限制: 1 Sec 内存限制: 128 MB
题目描述
Flow Free is a puzzle that is played on a 2D grid of cells, with some cells marked as endpoints of certain colors and the rest of cells being blank. To solve the puzzle, you have to connect each pair of colored endpoints with a path, following these rules:
there is a path connecting two points with the same color, and that path also has that color
all cells in the grid are used and each cell belongs to exactly one path (of the same color as the endpoints of the path)
The rules imply that different colored paths cannot intersect.
The path is defined as a connected series of segments where each segment connects two neighbouring cells. Two cells are neighbours if they share a side (so all segments are either horizontal or vertical). By these definitions and rules above, each colored cell will be an endpoint of exactly one segment and each blank cell will be an endpoint of exactly two segments.
In this problem we will consider only the 4×4 puzzle, with 3 or 4 pairs of colored endpoints given.
Your task is to determine if a given puzzle is solvable or not.
输入
The input consists of 4 lines, each line containing 4 characters. Each character is from the set {R, G,B, Y,W}whereW denotes the blank cells and the other characters denote endpoints with the specified color. You are guaranteed that there will be exactly 3 or 4 pairs of colored cells. If there are 3 colors in the grid, Y will be omitted.
输出
On a single line output either “solvable” or “not solvable” (without the quotes).
样例输入
RGBW
WWWW
RGBY
YWWW
样例输出
solvable

开始读错了题,没注意要连上所有的块。
暴力枚举每个W块的颜色,每种情况下从起点广搜终点,不用vis数组剪枝而采用记录路径(状压)可以保证搜到每种路径,搜到终点时判断是否走过了所有相同颜色的格子。
第二天仔细想想,还是写的太麻烦了,实际上直接深搜就好了…

#define IN_LB() freopen("F:\\in.txt","r",stdin)
#define IN_PC() freopen("C:\\Users\\hz\\Desktop\\in.txt","r",stdin)
#include <bits/stdc++.h>

using namespace std;
const 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值