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 ...
随机推荐
- Intel汇编指令格式解析
环境: win7_x64旗舰版.VS2015企业版 一.Intel保护模式.实地址模式和虚拟8086模式指令格式(x86) 图在Intel手册2.1章节 1.1)Instruction Prefixe ...
- Centos7快速安装docker
偶然间发现,docker的安装好容易啊 系统环境:centos7.3 yum源: docker:https://mirrors.aliyun.com/docker-ce/linux/centos/do ...
- windows远程登录报错 CredSSP不支持Oracle
https://support.microsoft.com/en-us/help/4093492/credssp-updates-for-cve-2018-0886-march-13-2018
- redux源码解读(一)
redux 的源码虽然代码量并不多(除去注释大概300行吧).但是,因为函数式编程的思想在里面体现得淋漓尽致,理解起来并不太容易,所以准备使用三篇文章来分析. 第一篇,主要研究 redux 的核心思想 ...
- C# partial 关健字说明
参考:http://blog.csdn.net/niemeiquan/article/details/7801803 1. 什么是局部类型? C# 2.0 引入了局部类型的概念.局部类型允许我们将一个 ...
- 【Oracle】group by 和partition by的区别
总结: group 单纯分组 partition 也能分组,但还具备累计的功能 order by 排序,与计算函数联用,需要累加计算 0.select * from test; ---测试数据 ...
- pandas第一课
pandas第一课 首先是数据的准备 movies.dat user.dat ratings.dat 注意,这些数据都是通过::来隔开每一列的,每一列有各自的含义 现在通过pandas来读入数据 首先 ...
- 记一个在移动端调试 web 页面的方法
1. 工具:Weinre 2. 安装:npm -g install weinre | npm install weinre -g --registry=https://registry.npm.tao ...
- 2018总结-->2019新目标
2018完成的事情: ①考到了驾照: ②刷了很多题,春季找到了实习,赚到了去日本旅游的经费和2019毕业租房的预算,最后签了offer: ③去了西安.天津.山西,看到了不一样的人和事: ④发了小论文, ...
- Win7下,nginx默认80端口被System占用,造成nginx启动报错
在win7 32位旗舰版下,启动1.0.8版本nginx,显示如下错误: 2012/04/02 13:55:59 [emerg] 7864#2376: bind() to 0.0.0.0:80 fai ...