题目描述
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)的更多相关文章

  1. ACM: FZU 2150 Fire Game - DFS+BFS+枝剪 或者 纯BFS+枝剪

    FZU 2150 Fire Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  2. codevs 3290 华容道(SPFA+bfs)

    codevs 3290华容道 3290 华容道 2013年NOIP全国联赛提高组 时间限制: 1 s  空间限制: 128000 KB 题目描述 Description 小 B 最近迷上了华容道,可是 ...

  3. poj3669 Meteor Shower(预处理+bfs)

    https://vjudge.net/problem/POJ-3669 先给地图a[][]预处理每个位置被砸的最小时间.然后再bfs. 纯bfs,还被cin卡了下时间.. #include<io ...

  4. 小结:bfs

    概要: 我们在初始状态要到达终止状态可以沿着同深度的向下搜索,这样范围覆盖更广,在解的深度较小的时候十分适用. 技巧及注意: 所有状态在转移后如果要打标记一定要在进队列前打!不要在出队列才打!否则就是 ...

  5. poj2312Battle City BFS

    题意: M行N列矩阵, 'Y'表示开始位置, 'T'表示目标位置, 从开始位置到目标位置至少需要走多少步,其中, 'S', 'R'表示不能走, 'B' 花费为2, 'E'花费为1. 思路:纯 BFS. ...

  6. POJ2251 Dungeon Master —— BFS

    题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  7. UVa 1601 || POJ 3523 The Morning after Halloween (BFS || 双向BFS && 降维 && 状压)

    题意 :w*h(w,h≤16)网格上有n(n≤3)个小写字母(代表鬼).要求把它们分别移动到对应的大写字母里.每步可以有多个鬼同时移动(均为往上下左右4个方向之一移动),但每步结束之后任何两个鬼不能占 ...

  8. 【wikioi】1026 逃跑的拉尔夫

    题目链接 算法:BFS 14.01.02 PS: 本人再次脑残,BFS又是写得那么脓肿,突然发现我原来什么搜索都是不会的呀.. //2014-02-05已更新 ******************** ...

  9. B - Dungeon Master POJ - 2251

    //纯bfs #include <iostream> #include <algorithm> #include <cstring> #include <cs ...

随机推荐

  1. JavaScript中的ononline事件和onoffline事件

    关于这个时间的描述到处都有,但基本上都是说离线在线什么的我一下子还没反应过来.后再在这里看到了一句话:"断开网络再联网试试,就可以看到连线的提示."这才反应过来,原来指的是网络状态 ...

  2. Cocostudio 1.4 实现的Demo程序源码

    开发环境是CocoStudio 1.4 + Cocos2dx 2.2.3  把项目文件放到Cocos2dx下的projects文件夹下就可以执行了 压缩包里面包括了 源码 和资源文件 1.DemoSh ...

  3. kotlin 编译 运行 hello world

    kotlin 编译器下载地址:https://github.com/JetBrains/kotlin/releases/tag/v1.3.31 解压:kotlin-compiler-1.3.31.zi ...

  4. Windbg 内核态调试用户态程序然后下断点正确触发方法(亲自实现发现有效)

    先开启真机内核态kernel调试 !process 0 0 svchost.exe 找到进程cid的地址 然后进入 .process /p  fffffa8032be2870 然后 .process ...

  5. 北京U3D外包团队 UE4红军抗战案例 Unity3D红军抗战案例 UE4下载和安装虚幻4游戏引擎

    刚完整UE4红军抗战案例 Unity3D红军抗战案例,有在线演示(版权关系不方便发图),有UE4或Unity项目定制外包开发的欢迎联系我们 进入虚幻4的官方主页(https://www.unreale ...

  6. 移动端css水平垂直居中

    水平垂直居中 1.margin 负值调整偏移实现 兼容性: 当前流行的使用方法. <div class="box"> <div class="conte ...

  7. 时间规划在Optaplanner上的实现

    在与诸位交流中,使用较多的生产计划和路线规划场景中,大家最为关注的焦点是关于时间的处理问题.确实,时间这一维度具有一定的特殊性.因为时间是一维的,体现为通过图形表示时,它仅可以通过一条有向直线来表达它 ...

  8. [UE4]Event Tick

    一.每一帧都会触发Event Tick事件,“Delta Seconds”参数表示当前帧说花费的时间 二.因为各种原因(比如卡帧等),每一帧所花费的时间并不是相同的

  9. symfony 踩坑之旅 视频实操从第九章开始

    1.annotation定义路由 @Route("/**",defaults={"name":"world"},requirements={ ...

  10. Oracle数据库中序列(SEQUENCE)的用法详解

    Oracle数据库中序列(SEQUENCE)的用法详解   在Oracle数据库中,序列的用途是生成表的主键值,可以在插入语句中引用,也可以通过查询检查当前值,或使序列增至下一个值.本文我们主要介绍了 ...