10分求调!
  • 板块P1683 入门
  • 楼主xywuyu
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/10/30 19:15
  • 上次更新2024/10/30 21:28:46
查看原帖
10分求调!
1395165
xywuyu楼主2024/10/30 19:15
#include<bits/stdc++.h>
using namespace std;
int n,m;bool t[100][100];char a[100][100];
int f(int y,int x)
{int e=0;

if (t[y+1][x]==0&&a[y+1][x]=='.')
{e+=1;t[y+1][x]=1;e+=f(y+1,x);}

if (t[y-1][x]==0&&a[y-1][x]=='.')
{e+=1;t[y-1][x]=1;e+=f(y-1,x);}

if (t[y][x+1]==0&&a[y][x+1]=='.')
{e+=1;t[y][x+1]=1;e+=f(y,x+1);}

if (t[y][x-1]==0&&a[y][x-1]=='.')
{e+=1;t[y][x-1]=1;e+=f(y,x-1);}

return e;}
int main()
{int w,b,c;
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]=='@')
{b=i;c=j;}}}
t[b][c]=1;

cout<<f(b,c)+1;
return 0;}
2024/10/30 19:15
加载中...