I am already the happiest girl in the world. What can I do at the end of the day? Can I save it? "
Title: https://www.luogu.org/problem/P1101
At the beginning of the question, I didn't understand what this meant. I even thought that every line was a judgement, and then directly confused me until a certain friend in the "base" room: Old_fox I dialed a few times before I understood the meaning of the question.
That is to say, a matrix, from each point, to eight directions, to see if yizhong can appear, and finally to turn all the impossible into *, is very simple.
The only thing that needs to be noticed is that after starting from each point, you can't change direction halfway, so——
Determine the direction outside the search first!
Upper Code:
#include<bits/stdc++.h> using namespace std; int dx[9]={0,1,-1,1,-1,1,-1,0,0}; int dy[9]={0,0,0,1,-1,-1,1,1,-1}; char a[105][105],ans[10]={"yizhong"}; bool b[105][105]={false}; int n,h[10][3]; void dfs(int z,int x,int y,int t)//There is no search in the big circle. sao Now! { int xx=x+dx[z]; int yy=y+dy[z]; if(a[xx][yy]==ans[t]) { h[t][1]=xx; h[t][2]=yy; if(t==6) for(int i=0;i<=6;i++) b[h[i][1]][h[i][2]]=true;//Set to 1 else dfs(z,xx,yy,t+1); h[t][1]=0; h[t][2]=0; } } int main() { scanf("%d",&n); for(int i=0;i<n;i++) scanf("%s",a[i]); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(a[i][j]=='y')//The prerequisite for entering the search is the current value y { for(int k=1;k<=8;k++)//Direction of judgement { if(a[i+dx[k]][j+dy[k]]=='i') { h[0][1]=i; h[0][2]=j; dfs(k,i,j,1);//Put the direction and current coordinates into the search } } } } } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(b[i][j]==true) printf("%c",a[i][j]); else printf("*"); } printf("\n"); }//output return 0; }