求调(除特殊情况外未什么全*)
查看原帖
求调(除特殊情况外未什么全*)
1830982
lai177820楼主2025/8/31 20:29

** 连样例都没过全是*号

8

qyizhong

gydthkjy

nwidghji

orbzsfgz

hhgrhwth

zzzzzozo

iwdfrgng

yyyygggg

全是*

怎么改大佬救救我吧!!orz

#include<bits/stdc++.h> using namespace std; int n; string s; char a[110][110]; int fx[8][2]={{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,-1},{-1,1}}; bool v[110][110]; int b[110][110]; void dfs(int x,int y,int p){ v[x][y]=true; for(int i=0,xx,yy;i<8;i++){ xx=x+fx[i][0],yy=fx[i][1]; if(v[xx][yy]==true||xx<1||xx>n||yy<1||yy>n||a[xx][yy]!=s[p]) continue; b[xx][yy]=1; v[xx][yy]=true; dfs(xx,yy,p+1); } } int main(){ cin>>n; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cin>>a[i][j]; } } s="yizhong"; dfs(1,1,1); for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(b[i][j]==1){ cout<<a[i][j]; }else{ cout<<"*"; } } cout<<endl; } /for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cout<<v[i][j]; } cout<<endl; }/ return 0; }

2025/8/31 20:29
加载中...