专栏文章
NC信奥 T4 病毒
个人记录参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @minhw0fv
- 此快照首次捕获于
- 2025/12/02 02:41 3 个月前
- 此快照最后确认于
- 2025/12/02 02:41 3 个月前
50分
CPP#include<bits/stdc++.h>
using namespace std;
int n,m;
char a[1020][1020];
int f[1021][1021];
int main(){
cin>>n>>m;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
cin>>a[i][j];
if(a[i][j]=='*'){
f[i][j] = 1;
}
}
}
while(1){
int cnt = 0;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
if(f[i][j-1]+f[i+1][j]+f[i-1][j]+f[i][j+1]>=2 && f[i][j]==0 && a[i][j]=='o') f[i][j] = 1,cnt++;
}
}
if(cnt==0) break;
}
for(int i = 1;i<=n;i++,cout<<endl){
for(int j = 1;j<=m;j++){
if(a[i][j]=='#') cout<<'#';
else{
if(f[i][j]) cout<<'*';
else cout<<'o';
}
}
}
return 0;
}
100分
CPP#include<bits/stdc++.h>
using namespace std;
int n,m;
char a[1001][1001];
int vis[1001][1001];
queue<pair<int,int> > q;
int main(){
cin>>n>>m;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
cin>>a[i][j];
}
}
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
if(a[i][j]=='*'){
q.push({i,j});
}
}
}
while(!q.empty()){
pair<int,int> tmp = q.front();
q.pop();
vis[tmp.first+1][tmp.second]++;
if(vis[tmp.first+1][tmp.second]>=2 && a[tmp.first+1][tmp.second]=='o'){
vis[tmp.first+1][tmp.second] = INT_MIN;
a[tmp.first+1][tmp.second] = '*';
q.push({tmp.first+1,tmp.second});
}
vis[tmp.first][tmp.second-1]++;
if(vis[tmp.first][tmp.second-1]>=2 && a[tmp.first][tmp.second-1]=='o'){
vis[tmp.first][tmp.second-1] = INT_MIN;
a[tmp.first][tmp.second-1] = '*';
q.push({tmp.first,tmp.second-1});
}
vis[tmp.first][tmp.second+1]++;
if(vis[tmp.first][tmp.second+1]>=2 && a[tmp.first][tmp.second+1]=='o'){
vis[tmp.first][tmp.second+1] = INT_MIN;
a[tmp.first][tmp.second+1] = '*';
q.push({tmp.first,tmp.second+1});
}
vis[tmp.first-1][tmp.second]++;
if(vis[tmp.first-1][tmp.second]>=2 && a[tmp.first-1][tmp.second]=='o'){
vis[tmp.first-1][tmp.second] = INT_MIN;
a[tmp.first-1][tmp.second] = '*';
q.push({tmp.first-1,tmp.second});
}
}
for(int i = 1;i<=n;i++,cout<<endl){
for(int j = 1;j<=n;j++) cout<<a[i][j];
}
return 0;
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...