http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2566

 #include <stdio.h>
#include <string.h>
char map[][];
int v[][];//用来标记某点所能到达的所有路径
int dir[][] = {{,},{,},{,-},{-,}};
int n,m;
void dfs(int x,int y,int t)
{
v[x][y] = t;
for (int i = ; i < ; i ++)
{
int dx = x + dir[i][];
int dy = y + dir[i][];
if (dx >= && dx < n && dy >= && dy < m && map[dx][dy]=='.'&&v[dx][dy]==-)
{
dfs(dx,dy,t);
}
}
}
int main()
{
int cnt;
while(~scanf("%d%d%d",&n,&m,&cnt))
{
int t = ;
memset(v,-,sizeof(v));
for (int i = ; i < n; i ++)
scanf("%s",map[i]);
for (int i = ; i < n; i ++)
{
for (int j = ; j < m; j ++)
{
if (map[i][j]=='.' && v[i][j]==-)
{
dfs(i,j,t++);
}
}
}
int x1,y1,x2,y2;
while(cnt--)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if (v[x1][y1]==-||v[x2][y2]==-||v[x1][y1]!=v[x2][y2])//若没被标记过或标记的D和J不是同一个数则不能相遇
printf("No\n");
else
{
if ((x2-x1+y2-y1)%==)
printf("Yes\n");
else
printf("No\n");
}
}
}
return ;
}

玩游戏(dfs)的更多相关文章

  1. bzoj4730: Alice和Bob又在玩游戏

    Description Alice和Bob在玩游戏.有n个节点,m条边(0<=m<=n-1),构成若干棵有根树,每棵树的根节点是该连通块内编号最 小的点.Alice和Bob轮流操作,每回合 ...

  2. cdoj 1136 邱老师玩游戏 树形背包

    邱老师玩游戏 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1136 Desc ...

  3. 【特殊的图+DP】【11月校赛】大家一起玩游戏

    大家一起玩游戏 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submi ...

  4. [UOJ266]Alice和Bob又在玩游戏

    [UOJ266]Alice和Bob又在玩游戏 Tags:题解 作业部落 评论地址 TAG:博弈 题意 不同于树的删边游戏,删掉一个点删去的是到根的路径 题解 这题只和计算\(SG\)有关,博弈的有关内 ...

  5. UOJ #266 【清华集训2016】 Alice和Bob又在玩游戏

    题目链接:Alice和Bob又在玩游戏 这道题就是一个很显然的公平游戏. 首先\(O(n^2)\)的算法非常好写.暴力枚举每个后继计算\(mex\)即可.注意计算后继的时候可以直接从父亲转移过来,没必 ...

  6. UESTC 2015dp专题 G 邱老师玩游戏 背包dp

    邱老师玩游戏 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descr ...

  7. [BZOJ4730][清华集训2016][UOJ266] Alice和Bob又在玩游戏

    题意:俩智障又在玩游戏.规则如下: 给定n个点,m条无向边(m<=n-1),保证无环,对于每一个联通块,编号最小的为它们的根(也就是形成了一片这样的森林),每次可以选择一个点,将其本身与其祖先全 ...

  8. JZOJ 5777. 【NOIP2008模拟】小x玩游戏

    5777. [NOIP2008模拟]小x玩游戏 (File IO): input:game.in output:game.out Time Limits: 1000 ms  Memory Limits ...

  9. [dp uestc oj] G - 邱老师玩游戏

    G - 邱老师玩游戏 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  10. TTTTTTTTTTTTT CDOJ 1136 邱老师玩游戏 树形dp

    邱老师玩游戏 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit St ...

随机推荐

  1. Python语言之函数

    1.函数的定义与调用 def function(x): print("function(%s)"%x) function("hello") #call the ...

  2. 06--Qt窗口布局

    Qt窗口布局 标签: qtlayout 2012-05-05 07:56 3076人阅读 评论(0) 收藏 举报  分类: Qt开发(33)  版权声明:本文为博主原创文章,未经博主允许不得转载. 布 ...

  3. HDU_1027_Ignatius and the Princess II_全排列

    Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ( ...

  4. python编写webservice接口

    1.pip install suds-jurko 2.pip install client #coding=utf-8 from suds.client import Client class Web ...

  5. / Vijos / 题库 /1250 / 最勇敢的机器人

    / Vijos / 题库 /1250 / 最勇敢的机器人 借鉴博客:http://www.cnblogs.com/chty/p/5830516.html 背景 Wind设计了很多机器人.但是它们都认为 ...

  6. Codeforces Round #468 Div. 2题解

    A. Friends Meeting time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  7. Aizu - 1379 Parallel Lines

    平行直线 题意:给出一些点,这些点两两相连成一条直线,问最多能连成多少条直线. 思路:暴力出奇迹!!记得当时比赛做这道题的时候一直依赖于板子,结果却限制了自己的思路,这得改.dfs直接暴力,但是需要将 ...

  8. 解决Scrapy抓取中文网页保存为json文件时中文不显示而是显示unicode的问题

    注意:此方法跟之前保存成json文件的写法有少许不同之处,注意区分 情境再现: 使用scrapy抓取中文网页,得到的数据类型是unicode,在控制台输出的话也是显示unicode,如下所示 {'au ...

  9. Python2 下Ubuntu linux Mac 安装 PyV8

    在pip install PyV8(注意区分大小写)时,出现了如下报错 command 'x86_64-linux-gnu-gcc' failed with exit status 1 解决方案: 百 ...

  10. 23.match_phrase_prefix实现search-time搜索推荐

    主要知识点: 搜索推荐的使用场景 用法 原理 一.搜索推荐的使用场景 搜索推荐,就是在你做搜索时,当你写出一部搜索词时,es会自提示接下来要写的词,比如当你在搜索hello w 时,如果es中有如下文 ...