6993: Dominoes(纯bfs)
题目描述
Orz likes to play dominoes. Now giving an n*m chessboard and k dominoes whose size are 1*2, Orz finds that there is exactly one grid empty, so that he can move dominoes without overlapping them. An initial situation is given, he wants to know how many final situation could be achieved, except the initial situation. Note every domino is different, as they have their own serial number. Since the answer may be very large, please output the answer modulo 1000000009.
输入
There will be multiple test cases. For each test case:
The first line contains three integers: n, m, k(n ≤ 9, m ≤ 10000).
The following k lines, each line contains four integers: a b c d, indicating that this domino occupies (a, b) and (c, d).
The input guarantees that the domino does not overlap, and there is exactly one empty grid.
输出
For each test cases, output the answer modulo 1000000009.
样例输入
5 5 12
1 1 2 1
1 2 2 2
1 3 2 3
1 4 1 5
2 4 2 5
3 4 3 5
3 1 3 2
4 1 4 2
5 1 5 2
4 3 5 3
4 4 5 4
4 5 5 5
样例输出
8
题意:类似华容道,问空格能在多少个位置出现
多米诺牌是1*2大小的,它可以横着放,也可以竖着放。
题目给出了k个多米诺牌的两个格子的坐标。
牌横着放的时候两个格子的横坐标相等,记为1;竖着放的时候两个格子的纵坐标相等,记为2。
空格可以上下左右四个方向移动:
如果空格能向上向下移动,那么,空格上下的牌必须是竖着放的;
如果空格能向左向右移动,那么,空格左右的牌必须是横着放的。
首先判断空格上下左右的牌是如何放置的,再判断空格能否移动。
标记空格走过的位置,空格出现的位置的状态是唯一的。
纯bfs,一层一层的搜。
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
using namespace std;
int MAP[][],ans,vis[][],n,m;
int dir[][]= {-,,,,,-,,};
struct node
{
int x,y;
};
queue<node>p;
int judge(int x,int y)
{
if(x>=&&x<=n&&y>=&&y<=m)
return ;
else
return ;
}
void bfs_(int tx,int ty)
{
node q;
q.x=tx,q.y=ty;
p.push(q);//将空格的位置入队列
vis[tx][ty]=;
int sx,sy;
while(!p.empty())
{
node temp;
temp=p.front();
p.pop();
vis[temp.x][temp.y]=;
node L;
sx = temp.x;
sy = temp.y;
if(MAP[sx-][sy]==&&judge(sx-,sy)&&vis[sx-][sy]==)//空格上面的牌是竖着放的,牌只能向下移动
{ //(sx-2,sy)是移动之后空格的坐标
ans++;
L.x=sx-,L.y=sy;
vis[sx-][sy]=;
p.push(L);
}
if(MAP[sx+][sy]==&&judge(sx+,sy)&&vis[sx+][sy]==)//空格下面的牌是竖着放的,牌只能向上移动
{
ans++;
L.x=sx+,L.y=sy;
vis[sx+][sy]=;
p.push(L);
}
if(MAP[sx][sy-]==&&judge(sx,sy-)&&vis[sx][sy-]==)//空格左边的牌是横着放的,牌只能向右移动
{
ans++;
L.x=sx,L.y=sy-;
vis[sx][sy-]=;
p.push(L);
}
if(MAP[sx][sy+]==&&judge(sx,sy+)&&vis[sx][sy+]==)//空格右边的牌是横着放的,牌只能向左移动
{
ans++;
L.x=sx,L.y=sy+;
vis[sx][sy+]=;
p.push(L);
}
} }
int main()
{
int k,tx,ty;
while(~scanf("%d%d%d",&n,&m,&k))
{
int x1,y1,x2,y2;
ans=;
memset(MAP,,sizeof(MAP));
memset(vis,,sizeof(vis));
for(int i=; i<=k; i++)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x1 == x2)
MAP[x1][y1]=,MAP[x2][y2]=;
else
MAP[x1][y1]=,MAP[x2][y2]=;
}
int flag = ;
for(int i=; i<=n; i++) //找到空格的位置
{
for(int j=; j<=m; j++)
{
if(MAP[i][j] == )
{
tx=i,ty=j;
flag = ;
break;
}
}
if(flag)
break;
}
bfs_(tx,ty);
printf("%d\n",ans);
}
return ;
}
6993: Dominoes(纯bfs)的更多相关文章
- ACM: FZU 2150 Fire Game - DFS+BFS+枝剪 或者 纯BFS+枝剪
FZU 2150 Fire Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- codevs 3290 华容道(SPFA+bfs)
codevs 3290华容道 3290 华容道 2013年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目描述 Description 小 B 最近迷上了华容道,可是 ...
- poj3669 Meteor Shower(预处理+bfs)
https://vjudge.net/problem/POJ-3669 先给地图a[][]预处理每个位置被砸的最小时间.然后再bfs. 纯bfs,还被cin卡了下时间.. #include<io ...
- 小结:bfs
概要: 我们在初始状态要到达终止状态可以沿着同深度的向下搜索,这样范围覆盖更广,在解的深度较小的时候十分适用. 技巧及注意: 所有状态在转移后如果要打标记一定要在进队列前打!不要在出队列才打!否则就是 ...
- poj2312Battle City BFS
题意: M行N列矩阵, 'Y'表示开始位置, 'T'表示目标位置, 从开始位置到目标位置至少需要走多少步,其中, 'S', 'R'表示不能走, 'B' 花费为2, 'E'花费为1. 思路:纯 BFS. ...
- POJ2251 Dungeon Master —— BFS
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
- UVa 1601 || POJ 3523 The Morning after Halloween (BFS || 双向BFS && 降维 && 状压)
题意 :w*h(w,h≤16)网格上有n(n≤3)个小写字母(代表鬼).要求把它们分别移动到对应的大写字母里.每步可以有多个鬼同时移动(均为往上下左右4个方向之一移动),但每步结束之后任何两个鬼不能占 ...
- 【wikioi】1026 逃跑的拉尔夫
题目链接 算法:BFS 14.01.02 PS: 本人再次脑残,BFS又是写得那么脓肿,突然发现我原来什么搜索都是不会的呀.. //2014-02-05已更新 ******************** ...
- B - Dungeon Master POJ - 2251
//纯bfs #include <iostream> #include <algorithm> #include <cstring> #include <cs ...
随机推荐
- streamreader 和 streamwriter 以及 string 与 memorystream 使用示例
经常用到,但老记不住,备忘一下 using (var ms = new MemoryStream()) { var sw = new StreamWriter(ms); sw.WriteLine(&q ...
- 为什么选择Go语言 GO语言都能做什么产品
Go语言,又称Golang,是Google开发的一款静态强类型.编译型.并发型,并具有垃圾回收机制的编程语言,它的运行速度非常之快,同时还有如下特性:具有一流的标准库.无继承关系.支持多核:同时它还有 ...
- RN 使用第三方字体
Android: 程序会尝试在 assets/fonts 目录下查找字体文件,如果没找到会使用默认的字体 所以将文件放到路径下才能生效! [project root]/android/app/src/ ...
- Nginx配置CI框架问题(Linux平台下Centos系统)
CI框架:官方文档 http://codeigniter.org.cn/user_guide/index.html CI框架的数据流程图如下: 其中:index.php作为入口文件,在安装好CI框架后 ...
- Python中多个列表与字典的合并方法
Python中多个列表与字典的合并方法 1多列表的合并 1)a+=b a=['] b = ['] a += b print(a) >>>['] 2) a.extend(b) a=[' ...
- [EasyUI]确认删除
//删除方法 function del() { var obj = getSelected(); if (obj) { $.messager.confirm('确认', '确定要删除:' + obj. ...
- VB 调用 webservice 出现:WSDLReader:Loading of the WSDL file failed HRESULT=0×80040154: 没有注册类别 解决方案
有些 VB 程序在调用 webservice 的时候出现“WSDLReader:Loading of the WSDL file failed HRESULT=0×80040154: 没有注册类别 ...
- 升级openssl 操作记录
openssl 是一群黑客最爱研究搞怪的一个软件为啥,据说openssl是一群数学家编写的一套算法 哈哈 好,说正事 openssl 经常发布补丁包,因为升级是避免不了的 步骤: 查看当前openss ...
- OpenCV中 常用 函数 的作用
1.CV_Assert函数作用: CV_Assert()若括号中的表达式值为false,则返回一个错误信息.
- 在Windows 10 64-bit上安装Windows SDK 7.1和.NET4
目的: 成功在window10上安装window sdk7.1 和 .NET Framework 4 需求: support some older software written in Visual ...