isomer__1 @ 2022-12-23 13:19:32
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <unordered_map>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
#include <deque>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int inf = 0x3f3f3f3f;
#define LOCAL
#define ft(i,n,m) for(int i=n;i<=m;i++)
#define fw(i,n,m) for(int i=n;i>=m;i--)
#define rr register int
#define mmp(x,y) make_pair(x,y)
#define lc(t) (t<<1)
#define rc(t) (t<<1|1)
int dx[5]={0,1,-1,0,0};
int dy[5]={0,0,0,1,-1};
int n;
int a[100][100],vis[100][100];
void dfs(int x,int y)
{
if(x<0||x>n+1||y<0||y>n+1||vis[x][y]!=0)
return;
vis[x][y]=1;
ft(i,1,4){
dfs(x+dx[i],y+dy[i]);
}
}
void solve()
{
cin>>n;
ft(i,1,n){
ft(j,1,n){
cin>>a[i][j];
if(a[i][j]==0)vis[i][j]=0;
else vis[i][j]=2;
}
}
dfs(0,0);
ft(i,1,n){
ft(j,1,n){
if(vis[i][j]==0)
cout<<2<<" ";
else cout<<a[i][j]<<" ";
}
cout<<endl;
}
}
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
solve();
return 0;
}
把dfs函数里的边界判定写成
if(x<1||x>n||y<1||y>n||vis[x][y]!=0)
就只能ac两个点,不懂为什么
by AC_CSP @ 2022-12-23 13:28:54
因为您标记的是外面,是可以打破界限的
by BreadCakeCheese @ 2023-01-05 20:13:40
因为从(0,0)开始往四个方向搜搜到的坐标都小于一,DFS就直接结束了