社区讨论
样例就不过,调了关
P1101单词方阵参与者 2已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @mhjo38y7
- 此快照首次捕获于
- 2025/11/04 05:43 4 个月前
- 此快照最后确认于
- 2025/11/04 05:43 4 个月前
CPP
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
char a[105][105];
char ans[105][105];
pair<ll,ll> temp[1000005];
string word="yizhong";
ll dx[]={0,1,-1,0,1,1,-1,-1};
ll dy[]={1,0,0,-1,-1,1,-1,1};
void dfs(ll idx,ll x,ll y,ll fx){
if (idx>=7){
cout<<1;
for(int i=0;i<7;i++){
pair<ll,ll> p=temp[i];
ans[p.first][p.second]=word[i];
}
return;
}
ll nx=x+dx[fx];
ll ny=y+dy[fx];
if (nx>=1 && ny>=1 && nx<=n && ny<=n && a[nx][ny]==word[idx]){
temp[idx].first=nx;
temp[idx].second=ny;
dfs(idx+1,nx,ny,fx);
}
}
int main(){
ios::sync_with_stdio(false);
ios_base::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n;
for (int i=1;i<=n;i++){
for (int j=1;j<=n;j++){
cin>>a[i][j];
ans[i][j]='*';
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(a[i][j]=='y'){
temp[0]={i,j};
for(int k=0;k<8;k++){
dfs(0,i,j,k);
}
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cout<<ans[i][j];
}
cout<<"\n";
}
return 0;
}
回复
共 5 条回复,欢迎继续交流。
正在加载回复...