题目描述
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. POJ1037 A decorative fence

    题意 Language:Default A decorative fence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 84 ...

  2. Vue01

    1.vue.js库的下载 vue.js是目前前端web开发最流行的工具库,由尤雨溪在2014年2月发布的. 另外几个常见的工具库:react.js /angular.js 官方网站: 中文:https ...

  3. idea调试代码跟踪到tomcat代码里面

    在POM.xml文件里面加上如下代码即可: <dependency> <groupId>org.apache.tomcat</groupId> <artifa ...

  4. MySQL表介绍

    MySQL InnoDB表介绍 一.索引组织表 在InnoDB引擎中,表都是根据主键顺序存放的.这种存储方式称为索引组织表,在InnoDB引擎中,每张表都有逐渐.如果没有显示定义主键,则引擎会按照以下 ...

  5. Day11字符串 title

    一.title 二.join------将字符串中的每一个元素按照指定分隔符进行拼接. 三.ljust rjust center    左.右.中间填充 四.lower  islower   uppe ...

  6. VirtualApk 插件入门小试

    1 官方资料 滴滴开源Android插件方案:VirtualAPK 2 宿主App集成方法 (1)在整个工程的build.gradle中添加依赖 dependencies { classpath 'c ...

  7. Chromium(Chrome) frame structure detail

    1. Chromium VS Chrome Chromium is an open-source Web browser project started by Google, to provide t ...

  8. 你云我云•兄弟夜谈会 第三季 企业IT架构

    你云我云•兄弟夜谈会 第三季 企业IT架构 你云我云•兄弟夜谈会 第二季 5G 你云我云•兄弟夜谈会 第一季 企业云 0. 概况 时间:2019年2月23日 22:00~23:30 主题:企业IT架构 ...

  9. tab$被删除恢复指南

    by 蔡建良 2019-2-25 经过长时间摸索,参考网上各类文章.今天终于让我成功恢复了oracle的sys.tab$表,并成功打开了数据库. 将此过程记录下来,与大家共享.如有疑问可联系我QQ: ...

  10. Centos 7环境下配置MySQL 5.7读写分离

    1.实验目的: 实现在Centos 7系统环境下,MySQL5.7读写分离. 2.实验条件: MySQL主服务器:Centos 7桌面环境,IP:10.10.11.31 MySQL从服务器:Cento ...