当前位置:网站首页>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");
}
}
边栏推荐
- Tcapulusdb Jun · industry news collection (IV)
- [tcapulusdb knowledge base] [list table] sample code of asynchronous scanning data
- 【owt】owt-client-native-p2p-e2e-test vs2017构建 4 : 第三方库的构建及链接p2pmfc.exe
- P1363 幻象迷宫(dfs)
- 电商如何借助小程序发力
- Bug STM32 advanced timer (haha, to tell you the truth, the hardware timer can't reflect its strength. In fact, I want to send the kernel timer. Just think about it. Take your time)
- Create a desktop shortcut to your appimage
- TRTC setaudioroute invalid problem
- 虫子 STM32 高级定时器 (哈哈我说实话硬件定时器不能体现实力,实际上想把内核定时器发上来的,一想算了,慢慢来吧)
- [advanced binary tree] AVLTree - balanced binary search tree
猜你喜欢
随机推荐
Software project management 8.4 Software project quality plan
Centos7 installing MySQL and configuring InnoDB_ ruby
[binary tree] 993 Cousins in Binary Tree
AI video cloud: a good wife in the era of we media
Halcon glue line detection - template matching, pose transformation, glue width, glue continuity detection
Common events for elements
Black horse PostgreSQL, why is it black in the end
Select sort method
背景彩带动画插件ribbon.js
Talk about memory model and memory order
[tcapulusdb knowledge base] [list table] delete all data sample codes in the list
What is the digital "true" twin? At last someone made it clear!
摆烂LuoGu刷题记
Swiftui component encyclopedia creating animated 3D card scrolling effects using Scrollview and geometryreader
[OWT] OWT client native P2P E2E test vs2017 build 2: test unit construction and operation
在 KubeSphere 上部署 Apache Pulsar
Which insurance company is the most cost-effective for purchasing serious illness insurance?
redis 精讲系列介绍八 - 淘汰策略
How to realize data transaction
Tcapulusdb Jun · industry news collection (III)









