3.17网易笔试
今天网易笔试的第二题案例有问题吧朋友们,自己在纸上模拟下来示例也不对😥😥😥
#网易笔试##网易##笔经#
#include<bits/stdc++.h>
using namespace std;
int m_size;
int max_st;
vector<pair<int,int>> dirs = {{1,1},{1,0},{1,-1},{0,1},{0,-1},
{-1,1},{-1,0},{-1,-1}};
void dfs(vector<string>& tmp,char a,int i,int j,int st,
vector<vector<int>>& reve,pair<int,int> dir,int step){
int ri = i + dir.first;
int rj = j + dir.second;
if(ri >= 0 && ri < m_size && rj >= 0 && rj < m_size){
if(tmp[ri][rj] != '-' && tmp[ri][rj] != a){
max_st = st;
}
dfs(tmp,a,ri,rj,st+1,reve,dir,step);
if(st < max_st && tmp[ri][rj] != '-' && step - reve[ri][rj] > 1){
if(tmp[ri][rj] == 'w') {
tmp[ri][rj] = 'b';
reve[ri][rj] = step;
}
else{
tmp[ri][rj] = 'w';
reve[ri][rj] = step;
}
}
}
return;
}
void operation(vector<string>& tmp,vector<vector<int>>& ope,
vector<vector<int>>& reve,int step){
if(step > ope.size()-1) return;
int x = ope[step][0];
int y = ope[step][1];
char now;
if(step % 2 == 0) tmp[x][y] = 'w';
else tmp[x][y] = 'b';
for(auto dir : dirs){
max_st = 0;
dfs(tmp,tmp[x][y],x,y,1,reve,dir,step);
}
operation(tmp,ope,reve,step+1);
}
void solution(vector<string>& tmp,vector<vector<int>>& ope){
m_size = tmp.size();
vector<vector<int>> reve(tmp.size(),vector<int>(tmp.size(),-2));
operation(tmp,ope,reve,0);
for(auto tm : tmp){
cout<<tm<<endl;
}
cout<<"END"<<endl;
}
int main(){
int T;
cin>>T;
while(T--){
int n,m;
cin>>n>>m;
vector<string> tmp(n,"");
vector<vector<int>> ope(m,vector<int>(2,0));
for(int i = 0;i < n;i++){
cin>>tmp[i];
}
for(int i = 0;i < m;i++){
cin>>ope[i][0]>>ope[i][1];
}
solution(tmp,ope);
}
} #网易笔试##网易##笔经#
查看23道真题和解析

