求助,顶给您点关注,就是很诡异
查看原帖
求助,顶给您点关注,就是很诡异
421128
Addrian楼主2023/11/5 10:04
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<map>
using namespace std;
struct node{
	int x,y,dj;
};
int n;
string a1[105];
char a[105][105];
int dx1[10]={0,1,0,-1,0,1,-1,1,-1};
int dy1[10]={0,0,1,0,-1,1,-1,-1,1};
queue<node> q;
map<char,int> zh;
int x1,y1;
int bbf[105][105];
int bfs(int dx,int dy){
	node cs;
	cs.x=x1;
	cs.y=y1;
	cs.dj=2;
	q.push(cs);
	node t,tt;
	while(!q.empty()){
		t=q.front();
		q.pop();
		if(tt.dj==7){
			return 1;
		}
		tt.x=t.x+dx;
		tt.y=t.y+dy;
		tt.dj=t.dj+1;
		if(tt.x<1||tt.x>n||tt.y<1||tt.y>n){
			return 0;
		}
		if(zh[a[tt.x][tt.y]]==tt.dj){
			q.push(tt);
		}else{
			return 0;
		}
	}
}
int main(){
	cin>>n;
	zh['y']=1;zh['i']=2;zh['z']=3;zh['h']=4;zh['o']=5;zh['n']=6;zh['g']=7;
	for(int i=1;i<=n;i++){
		cin>>a1[i];
		for(int j=1;j<=n;j++){
			a[i][j]=a1[i][j-1];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(zh[a[i][j]]==1){
				//cout<<"giao"<<i<<" "<<j<<endl;
				for(int q=1;q<=8;q++){
					x1=i+dx1[q];
					y1=j+dy1[q];
					if(zh[a[x1][y1]]==2){
						//cout<<"enmi"<<x1<<" "<<y1<<endl;
						if(bfs(dx1[q],dy1[q])==1){
							for(int p=0;p<=6;p++){
								x1=i+dx1[q]*p;
								y1=j+dy1[q]*p;
								bbf[x1][y1]=1;
							}
						}
					}
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(bbf[i][j]==1){
				cout<<a[i][j];
			}else{
				cout<<"*";
			}
		}
		cout<<endl;
	}
	return 0;
}

加上57行注释 样例 8

qyizhong

gydthkjy

nwidghji

orbzsfgz

hhgrhwth

zzzzzozo

iwdfrgng

yyyygggg 输出

*yizhong

gy******

n*i*****

o**z****

hh

z****o**

i*****n*

y******g 不加上 *yizhong

gy******

n*i*****

o**z****

hh

z****o**

i*****n*

yy*****g

?????????

应该是我的问题吧

2023/11/5 10:04
加载中...