acgo题库
  • 首页
  • 题库
  • 题单
  • 竞赛
  • 讨论
  • 排行
  • 团队
  • 备赛专区

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情题解(0)讨论(0)提交记录(0)
  • 逆向广搜

    #include<iostream> #include<queue> #include<vector> using namespace std; const int maxn = 1e3 + 15; int n,m,ans,sx,sy,ax[5] = {0,1,-1,0,0},ay[5] = {0,0,0,1,-1}; bool vis[maxn][maxn]; char mp[maxn][maxn]; struct node{ int x,y; }; int main(){ vector<node> s; cin >> n >> m; for(int i = 1;i <= n;i++){ for(int j = 1;j <= m;j++){ cin >> mp[i][j]; if(mp[i][j] == 'o') s.push_back({i,j}); } } queue<node> q; for(int i = 0;i < s.size();i++){ q.push(s[i]); vis[s[i].x][s[i].y] = 1; } while(!q.empty()){ node r = q.front(); q.pop(); vis[r.x][r.y] = 1; ans++; for(int i = 1;i <= 4;i++){ int nx = r.x + ax[i],ny = r.y + ay[i]; if(nx < 1 || ny < 1 || nx > n || ny > m || vis[nx][ny]) continue; if((i == 1 && mp[nx][ny] == 'u') || (i == 2 && mp[nx][ny] == 'd') || (i == 3 && mp[nx][ny] == 'l') || (i == 4 && mp[nx][ny] == 'r')){ q.push({nx,ny}); vis[nx][ny] = 1; } } } cout << ans; return 0; }

    userId_undefined

    137****0822

    时间刺客
    3阅读
    0回复
    1点赞
首页