当前位置:网站首页>P1363 phantom maze (DFS)
P1363 phantom maze (DFS)
2022-06-23 04:19:00 【Harris-H】
P1363 Phantom maze (dfs)
If the point after the mold is taken is taken twice , Then there are rings .
Note that the two points must be different before taking the mold .
So we maintain the position of each point before taking the mold .
Then use the tag array to maintain whether the position has been passed .
And then each special judgment dfs that will do .
Time complexity : O ( n ∗ m ∗ 4 ) O(n*m*4) O(n∗m∗4)
Code reference solution
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
const int hashmod[4] = {
402653189,805306457,1610612741,998244353};
#define mst(a,b) memset(a,b,sizeof a)
#define db double
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define x first
#define y second
#define pb emplace_back
#define SZ(a) (int)a.size()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr)
void Print(int *a,int n){
for(int i=1;i<n;i++)
printf("%d ",a[i]);
printf("%d\n",a[n]);
}
template <typename T> //x=max(x,y) x=min(x,y)
void cmx(T &x,T y){
if(x<y) x=y;
}
template <typename T>
void cmn(T &x,T y){
if(x>y) x=y;
}
int main(){
return 0;
}
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN = 1500 + 1;
const int dx[4] = {
1, -1, 0, 0};
const int dy[4] = {
0, 0, 1, -1};
int n, m;
int st_x, st_y;
int vis[MAXN][MAXN][3];
bool fl, a[MAXN][MAXN];
char ch;
void dfs(int x, int y, int lx, int ly) {
if(fl) return;
if(vis[x][y][0] && (vis[x][y][1]!=lx || vis[x][y][2]!=ly)) {
fl = 1;
return;
}
vis[x][y][1] = lx, vis[x][y][2] = ly, vis[x][y][0] = 1;
for(int i=0; i<4; ++i) {
int xx = (x + dx[i] + n) % n, yy = (y + dy[i] + m) % m;
int lxx = lx + dx[i], lyy = ly + dy[i];
if(!a[xx][yy]) {
if(vis[xx][yy][1]!=lxx || vis[xx][yy][2]!=lyy || !vis[xx][yy][0])
dfs(xx, yy, lxx, lyy);
}
}
}
int main() {
ios::sync_with_stdio(false);
while(cin >> n >> m) {
fl = 0;
memset(a, 0, sizeof(a));
memset(vis, 0, sizeof(vis));
for(int i=0; i<n; ++i)
for(int j=0; j<m; ++j) {
cin >> ch;
if(ch == '#') a[i][j] = 1;
if(ch == 'S') st_x = i, st_y = j;
}
dfs(st_x, st_y, st_x, st_y);
if(fl) puts("Yes");
else puts("No");
}
}
边栏推荐
- 怎么使用Shell脚本实现监测文件变化
- Getting started with tensorflow
- What is the potential of dmail based on Web3.0? First round financing of $10 million?
- 2022年的软件开发:首席信息官应该知道的五个现实
- For patch rollback, please check the cbpersistent log
- 虫子 日期类 上 太子语言
- Centos7 installing MySQL and configuring InnoDB_ ruby
- node+express如何操作cookie
- x64dbg 基本使用技巧
- January 17, 2022: word rule II. Give you a pattern and a character
猜你喜欢
![[advanced binary tree] AVLTree - balanced binary search tree](/img/a5/aef68dd489ef5545e5b11ee2d3facc.png)
[advanced binary tree] AVLTree - balanced binary search tree

【owt】owt-client-native-p2p-e2e-test vs2017构建2 :测试单元构建及运行

城链科技董事长肖金伟:践行数据经济系国家战略,引领数字时代新消费发展!

Ideal car × Oceanbase: when new forces of car building meet new forces of database

MySQL common instructions

Full analysis of embedded software testing tool tpt18 update

AI video cloud vs narrowband HD, who is the favorite in the video Era

摆烂LuoGu刷题记

【owt】owt-client-native-p2p-e2e-test vs2017构建 4 : 第三方库的构建及链接p2pmfc.exe

Insert sort directly
随机推荐
svg d3.js生成tree树状图
Tcapulusdb Jun · industry news collection (IV)
深度学习 简介
[greed] leetcode991 Broken Calculator
京东云分布式数据库StarDB荣获中国信通院 “稳定性实践先锋”
How to realize data transaction
折半查找法
冒泡排序法
两招提升硬盘存储数据的写入效率
深度学习 TensorFlow入门
移动端城市列表排序js插件vercitylist.js
The new version of Kali switches the highest account
P1347 排序(topo)
[pycharm] ide Eval resetter
[tcapulusdb knowledge base] [list table] example code of batch deleting data at specified location in the list
Pytorch---Pytorch进行自定义Dataset
What is the potential of dmail based on Web3.0? First round financing of $10 million?
Form development mode
嵌入式软件测试工具TPT18更新全解析
虫子 日期类 上 太子语言