CCF 模拟E DFS深搜
http://115.28.138.223:81/view.page?opid=5
这道题问的很怪. 起点DFS,每一个点还要DFS一次,统计不能到终点的个数
数据量不大这样做也能AC
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int x,y,ax,ay,bx,by;//'#'0, '+'1, '-'2, '|'3, '.'4, 'S', 'T'
int x1[]={,-,, };
int y1[]={, ,,-};
int d[][],lable[][],labll[][];
int numb,shit=;
void ddfs(int xx,int yy)
{
if(shit==){return;}
if(xx==by&&yy==bx){shit=;return;}
if(labll[xx][yy]==||d[xx][yy]==||xx<||yy<){return;}
labll[xx][yy]=;
if(d[xx][yy]==)
{
for(int i=;i<;i++)
{
ddfs(xx+x1[i],yy+y1[i]);
if(shit==){return;}
}
}
if(d[xx][yy]==)
{
for(int i=;i<;i++)
{
ddfs(xx+x1[i],yy+y1[i]);
if(shit==){return;}
}
}
if(d[xx][yy]==)
{
for(int i=;i<;i++)
{
ddfs(xx+x1[i],yy+y1[i]);
if(shit==){return;}
}
}
if(d[xx][yy]==)
{
for(int i=;i<;i++)
{
ddfs(xx+x1[i],yy+y1[i]);
if(shit==){return;}
}
}
return;
}
void dfs(int xx,int yy)//3 0
{
if(lable[xx][yy]==||d[xx][yy]==||xx<||yy<){return;}
lable[xx][yy]=;
for(int i=;i<y;i++)
{
for(int j=;j<x;j++)
{
labll[i][j]=;
}
}
shit=;
ddfs(xx,yy);
if(shit==){numb++;}
if(d[xx][yy]==)
{
for(int i=;i<;i++)
{
dfs(xx+x1[i],yy+y1[i]);
}
}
if(d[xx][yy]==)
{
for(int i=;i<;i++)
{
dfs(xx+x1[i],yy+y1[i]);
}
}
if(d[xx][yy]==)
{
for(int i=;i<;i++)
{
dfs(xx+x1[i],yy+y1[i]);
}
}
if(d[xx][yy]==)
{
for(int i=;i<;i++)
{
dfs(xx+x1[i],yy+y1[i]);
}
}
return;
} int main()
{
while(cin>>y>>x)
{
char c;
numb=;
for(int i=;i<y;i++)
{
for(int j=;j<x;j++)
{
cin>>c;
if(c=='S'){d[i][j]=;ax=j;ay=i;}
if(c=='T'){d[i][j]=;bx=j;by=i;}
if(c=='#'){d[i][j]=;}
if(c=='+'){d[i][j]=;}
if(c=='-'){d[i][j]=;}
if(c=='|'){d[i][j]=;}
if(c=='.'){d[i][j]=;}
}
}
shit=;
ddfs(ay,ax);
if(shit==){cout<<"I'm stuck!"<<endl;continue;}
dfs(ay,ax);
cout<<numb<<endl;
for(int i=;i<y;i++)
{
for(int j=;j<x;j++)
{
d[i][j]=lable[i][j]=;
}
}
}
return ;
}
CCF 模拟E DFS深搜的更多相关文章
- CodeM美团点评编程大赛初赛B轮 黑白树【DFS深搜+暴力】
[编程题] 黑白树 时间限制:1秒 空间限制:32768K 一棵n个点的有根树,1号点为根,相邻的两个节点之间的距离为1.树上每个节点i对应一个值k[i].每个点都有一个颜色,初始的时候所有点都是白色 ...
- DFS 深搜专题 入门典例 -- 凌宸1642
DFS 深搜专题 入门典例 -- 凌宸1642 深度优先搜索 是一种 枚举所有完整路径以遍历所有情况的搜索方法 ,使用 递归 可以很好的实现 深度优先搜索. 1 最大价值 题目描述 有 n 件物品 ...
- 【DFS深搜初步】HDOJ-2952 Counting Sheep、NYOJ-27 水池数目
[题目链接:HDOJ-2952] Counting Sheep Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- DFS深搜——Red and Black——A Knight's Journey
深搜,从一点向各处搜找到全部能走的地方. Problem Description There is a rectangular room, covered with square tiles. Eac ...
- Red and Black(DFS深搜实现)
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
- poj 2386:Lake Counting(简单DFS深搜)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18201 Accepted: 9192 De ...
- UVA 165 Stamps (DFS深搜回溯)
Stamps The government of Nova Mareterrania requires that various legal documents have stamps attac ...
- HDU_1241 Oil Deposits(DFS深搜)
Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...
- 解救小哈——dfs深搜
问题描述: 小哈去玩迷宫,结果迷路了,小哼去救小哈.迷宫由n行m列的单元格组成(n和m都小于等于50),每个单元格要么是空地,要么是障碍物. 问题:帮小哼找到一条从迷宫的起点通往小哈所在位置的最短路径 ...
随机推荐
- 11 Clever Methods of Overfitting and how to avoid them
11 Clever Methods of Overfitting and how to avoid them Overfitting is the bane of Data Science in th ...
- js数字、字符串、数组之间的转化
1.数组转字符串 var a, b; a = ,,,,); b = a.join("-"); 2.字符串转数组 var s = "abc,abcd,aaa"; ...
- xmanager远程桌面连接Linux
远程桌面连接Linux,两种工具:vnc.xmanager xmanager使用参考如下,暂未整理: Xmanager连接Centos的远程桌面 | 大爱 http://lovesoo.org/xma ...
- 数据库操作事务IsolationLevel 枚举
成员名称 说明 Chaos 无法覆盖隔离级别更高的事务中的挂起的更改. ReadCommitted 在正在读取数据时保持共享锁,以避免脏读,但是在事务结束之前可以更改数据,从而导致不可重复 ...
- Asp.NET的Trace追踪
http://m.blog.csdn.net/article/details?id=7026402 当我们扑捉程序错误时,调试器是开发者们最得力的助手.然而,ASP.NET的跟踪,在调试时是一个很棒的 ...
- js实现点击增加文本输入框
html代码: <ul id="ulid21" > <li id="li11" >问卷选项设置:</li> </ul& ...
- MV*模式的个人理解
MV*模式主要解决的问题就是 View代码难以维护的问题. MV*模式将View中的逻辑分离出去,形成一个弱逻辑的易于维护的视图. MV*中的*是Model和View的桥梁,负责保持Model和Vie ...
- Hibernate 查询MatchMode的四种模式
Hibernate 查询MatchMode的四种模式 MatchMode.START:字符串在最前面的位置.相当于"like 'key%'" MatchMode.END:字符串在最 ...
- webservice 服务端例子+客户端例子+CXF整合spring服务端测试+生成wsdl文件 +cxf客户端代码自动生成
首先到CXF官网及spring官网下载相关jar架包,这个不多说.webservice是干嘛用的也不多说. 入门例子 模拟新增一个用户,并返回新增结果,成功还是失败. 大概的目录如上,很简单. Res ...
- CocoaLumberjack
刚学iOS时候,调试找问题的时候一般就两种方式. 1.输出NSLog日志. 2.打断点,一步一步查看问题,查找崩溃点所在的方法,再进一步查看崩溃具体原因,稍微高级一点的就在控制台用命令打印各种参数. ...