Untitled
unknown
plain_text
a year ago
1.0 kB
1
Indexable
Never
#include<bits/stdc++.h> #define DilligentArch() ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0); #define testcase(t) int t; cin>>t; while(t--) #define pb push_back typedef long long ll; using namespace std; const int N = 1e5+10; vector<int>g[N]; bool cat[N]; ll ct=0; ll n,m; char arr[20][20]; void dfs(ll i, ll j) { if(i<0 or j<0) return; if(i>=n or j>=m) return; if(arr[i][j]!= '.' )return; ct++; arr[i][j]='#'; dfs(i-1,j); dfs(i+1,j); dfs(i,j-1); dfs(i,j+1); } void solve() { cin>>n>>m; ll x,y; for(ll i=0; i<n; i++) { for(ll j=0; j<m; j++) { cin>>arr[i][j]; if(arr[i][j]=='@') { x=i; y=j; } } } arr[x][y]='.'; dfs(x,y); cout<<ct<<endl; } int main() { DilligentArch() ll t; cin>>t; for(ll i=1; i<=t; i++) { cout<< "Case "<<i<< ": "; solve(); ct=0; } }