社区讨论
求助,顶给您点关注,就是很诡异
P1101单词方阵参与者 2已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @loku09ft
- 此快照首次捕获于
- 2023/11/05 10:05 2 年前
- 此快照最后确认于
- 2023/11/05 11:23 2 年前
CPP
#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
?????????
应该是我的问题吧
回复
共 3 条回复,欢迎继续交流。
正在加载回复...