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

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

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

    userId_undefined

    Tian

    倔强青铜
    2阅读
    1回复
    0点赞
  • 题解[DFS](求赞)

    #include<bits/stdc++.h> using namespace std; int n,m,t,ans=0; int sx,sy,fx,fy; char a[50][50]; bool vis[50][50]; int dir_x[4]={-1,1,0,0}; int dir_y[4]={0,0,-1,1}; bool check(int x,int y){ return x>=1&&x<=n&&y>=1&&y<=m&&a[x][y]0&&vis[x][y]0; } void dfs(int x,int y){ if(xfx&&yfy){ ans++; return ; } for(int i=0;i<4;i++){ int nx=x+dir_x[i]; int ny=y+dir_y[i]; if(check(nx,ny)){ vis[nx][ny]=1; dfs(nx,ny); vis[nx][ny]=0; } } } int main(){ cin>>n>>m>>t>>sx>>sy>>fx>>fy; while(t--){ int x,y; cin>>x>>y; a[x][y]=1; } vis[sx][sy]=1; dfs(sx,sy); cout<<ans; return 0; }

    userId_undefined

    c++王子

    循环·循环打卡人
    3阅读
    0回复
    0点赞
  • 题解

    userId_undefined

    枫岚

    出道萌新秩序白银快乐小狗时空双修者GESP4级
    1阅读
    0回复
    0点赞
  • ococococococcocococo

    #include <bits/stdc++.h> using namespace std; int n,m,t,p,q,sx,sy,fx,fy,a[10][10],vis[10][10],ans; int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1}; bool check(int x,int y){ if(x>=1 && x<=n && y>=1 && y<=m){ if(vis[x][y]0){ if(a[x][y]0){ return 1; } } } return 0; } void dfs(int x,int y){ if(xfx&& yfy){ ans++; return ; } vis[x][y]=1; for(int i=0;i<4;i++){ int newx=x+dx[i],newy=y+dy[i]; if(check(newx,newy)) dfs(newx,newy); } vis[x][y]=0; } int main(){ cin>>n>>m>>t; cin>>sx>>sy>>fx>>fy; while(t--){ cin>>p>>q; a[p][q]=1; } dfs(sx,sy); cout<<ans; return 0; }

    userId_undefined

    复仇者_Y38╋════━➢

    0阅读
    0回复
    0点赞

共24条

  • 1
  • 2
20条/页
跳至页
暂无数据

提交答案之后,这里将显示提交结果~

首页