codeforces793 B. Igor and his way to work (dfs)
题目链接:codeforces793 B. Igor and his way to work (dfs)
求从起点到终点转方向不超过两次是否有解,,好水啊,感觉自己代码好搓。。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<limits.h>
#define CLR(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long ll;
const int N = ;
int n, m;
int sx, sy, ex, ey;int flag;
char s[N][N];
int vis[N][N][][];
void dfs(int x, int y, int d, int turn) {//上下:d = 1,左右:d = 2
if(turn > || vis[x][y][d][turn]) return;
if(x == ex && y == ey) {
flag = true;
return;
}
vis[x][y][d][turn] = ;
if(x- >= && s[x-][y] != '*' && !vis[x-][y][][turn+(d==)]) {
dfs(x-, y, , turn + (d==));
}
if(x+ < n && s[x+][y] != '*' && !vis[x+][y][][turn+(d==)]) {
dfs(x+, y, , turn + (d==));
}
if(y- >= && s[x][y-] != '*' && !vis[x][y-][][turn+(d==)]) {
dfs(x, y-, , turn + (d==));
}
if(y+ < m && s[x][y+] != '*' && !vis[x][y+][][turn+(d==)]) {
dfs(x, y+, , turn + (d==));
}
}
int main() {
int i, j;
scanf("%d%d ", &n, &m);
for(i = ; i < n; ++i) {
scanf("%s", s[i]);
for(j = ; j < m; ++j) {
if(s[i][j] == 'S') {sx = i; sy = j;}
else if(s[i][j] == 'T') {ex = i; ey = j;}
}
}
flag = ;
CLR(vis, );
dfs(sx, sy, , );
if(flag) puts("YES");
else puts("NO");
return ;
}
codeforces793 B. Igor and his way to work (dfs)的更多相关文章
- codeforces 793B - Igor and his way to work(dfs、bfs)
题目链接:http://codeforces.com/problemset/problem/793/B 题目大意:告诉你起点和终点,要求你在只能转弯两次的情况下能不能到达终点.能就输出“YES”,不能 ...
- Educational Codeforces Round 1 D. Igor In the Museum bfs 并查集
D. Igor In the Museum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598 ...
- Igor In the Museum(搜搜搜151515151515******************************************************1515151515151515151515)
D. Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standar ...
- codeforces 793B. Igor and his way to work
B. Igor and his way to work time limit per test 3 seconds memory limit per test 256 megabytes input ...
- 【CodeForces - 598D】Igor In the Museum(bfs)
Igor In the Museum Descriptions 给你一个n*m的方格图表示一个博物馆的分布图.每个方格上用'*'表示墙,用'.'表示空位.每一个空格和相邻的墙之间都有一幅画.(相邻指的 ...
- Codeforces 598D:Igor In the Museum
D. Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standar ...
- [BFS]Codeforces Igor In the Museum
Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standard ...
- F. Igor and Interesting Numbers
http://codeforces.com/contest/747/problem/F cf #387 div2 problem f 非常好的一道题.看完题,然后就不知道怎么做,感觉是dp,但是不知道 ...
- Educational Codeforces Round 1(D. Igor In the Museum) (BFS+离线访问)
题目链接:http://codeforces.com/problemset/problem/598/D 题意是 给你一张行为n宽为m的图 k个询问点 ,求每个寻问点所在的封闭的一个上下左右连接的块所能 ...
随机推荐
- ES6展开运算符(...)
数组字面量中使用展开运算符 我们可以这样合并数组: var arr1=['a','b','c']; var arr2=[...arr1,'d','e']; //['a','b','c','d','e' ...
- 栈C++实现
栈的核心是LIFO(Last In First Out),即后进先出 出栈和入栈只会对栈顶进行操作,栈底永远为0.如果是入栈,要将入栈元素赋值给栈数组,再将栈顶上移一位:出栈时要先将栈顶下移一位,再将 ...
- HDU 5700——区间交——————【线段树+枚举】
区间交 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...
- radio 实现点击两次 第一次点击选中第二次点击取消
由于项目的需求,要求radio点击两次后为取消状态,不方便修改为checkbox,可以用正面的方法实现. // jquery $('input:radio').click(function(){ // ...
- mysql case when的使用
SELECT (CASE payType WHEN 1 THEN '微信' WHEN 2 THEN '支付宝' ELSE '余额' END) as type, count(payType) FROM ...
- 廖雪峰JavaScript练习题2
请把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字.输入:['adam', 'LISA', 'barT'],输出:['Adam', 'Lisa', 'Bart'] 肯定有更简单的方法, ...
- Python入门-函数进阶
昨天我们简单的了解了函数的定义,调用,以及传参,其实还有一个更重要的传参:动态传参,让我们继续昨天没有说完的,以及今天我要分享的东西. 一.动态传参 之前我们说过了传参,如果我们需要给一个函数传参,而 ...
- Java设计模式—观察者模式
观察者模式(Observer Pattern)也叫做发布订阅模式(Publish/subscribe). 其定义如下: 定义对象间一种一对多的依赖关系,使得每当一个对象改变状态,则所有依赖于它的对象都 ...
- 十四、css动画基础知识
引用动画的方式: 1.轻量动画: cubic-bezier(0.165, 0.840, 0.440, 1.000);//加上贝塞尔曲线使动画运动起来更加平滑 2..scrollNews,.m-tr ...
- 获取当前时间CTime
std::string getcurtime(){ USES_CONVERSION; CTime z_CurTime; CString z_TimeStr; z_CurTime = CTime::Ge ...