Advertisement
Saleh127

Lo 1012

Sep 25th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. char xx[22][22];
  6. ll r,c,ans;
  7. int v[100][100];
  8. void dfs(ll x,ll y)
  9. {
  10. if(v[x][y]==1) return;
  11. v[x][y]=1;
  12.  
  13. if(x+1<r && xx[x+1][y]!='#' && v[x+1][y]==0)
  14. {
  15. ans++;
  16. dfs(x+1,y);
  17. }
  18. if(x-1>=0 && xx[x-1][y]!='#' && v[x-1][y]==0)
  19. {
  20. ans++;
  21. dfs(x-1,y);
  22. }
  23. if(y+1<c && xx[x][y+1]!='#' && v[x][y+1]==0)
  24. {
  25. ans++;
  26. dfs(x,y+1);
  27. }
  28. if(y-1>=0 && xx[x][y-1]!='#' && v[x][y-1]==0)
  29. {
  30. ans++;
  31. dfs(x,y-1);
  32. }
  33. }
  34.  
  35. int main()
  36. {
  37. ios_base::sync_with_stdio(0);
  38. cin.tie(0);cout.tie(0);
  39.  
  40. test
  41. {
  42. ll z=0,i,j,x,y;
  43. cin>>c>>r;
  44. memset(v,0,sizeof(v));
  45. for(i=0;i<r;i++)
  46. {
  47. for(j=0;j<c;j++)
  48. {
  49. cin>>xx[i][j];
  50. if(xx[i][j]=='@')
  51. {
  52. x=i;
  53. y=j;
  54. }
  55. }
  56. }
  57. ans=1;
  58. dfs(x,y);
  59.  
  60. cout<<"Case "<<cs<<": "<<ans<<endl;
  61. }
  62. return 0;
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement