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

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情题解(0)讨论(0)提交记录(0)
  • 正经题解|水流问题

    【算法分析】 可以考虑从大西洋和太平洋开始搜索。从大西洋开始搜索可以相当于从与大西洋相邻的位置开始搜索,搜索的规则就是当前位置的值小于等于搜索位置的值。用一个数组存储有这个位置可以流到海洋的数目,因此当搜索到一个位置的时候需要将这个数组的值加一,从太平洋也是类似的。 【参考代码】 【时间复杂度】 O(n∗m)O(n*m)O(n∗m) 【预计得分】 100pts100pts100pts

    userId_undefined

    AC君

    管理员
    倔强青铜
    55阅读
    0回复
    0点赞
  • 题解

    相似题目:滑雪 这道题可以遍历每一个点并都进行bfs 因为说是小于等于,所以标记数组可以不开,只要能规避上个数字与这个数字相等导致的重复入队就行 代码如下

    userId_undefined

    不会C++的一只屑生姜

    倔强青铜
    32阅读
    0回复
    2点赞
  • 题解

    方法一,稍微会有残留 #include<bits/stdc++.h> using namespace std; int dx[]={-1,1,0,0}; int dy[]={0,0,-1,1}; int a[1002][1002],m,n; bool vis[1050][1050]; bool vis1[1050][1050]; struct node{ int x,y; }; queue<node>q; void bfs(queue<node>q,bool vis[1050][1050]){ while(!q.empty()){ node tmp=q.front(); q.pop(); for(int i=0;i<4;i++){ int tx=tmp.x+dx[i]; int ty=tmp.y+dy[i]; if(tx<1||tx>n||ty<1||ty>m)continue; if(vis[tx][ty])continue; if(a[tx][ty]<a[tmp.x][tmp.y])continue; vis[tx][ty]=true; q.push(node{tx,ty}); } int main(){ }

    userId_undefined

    小ZUZ

    荣耀黄金
    26阅读
    0回复
    1点赞
首页