- #include <bits/stdc++.h>
- using namespace std;
- int ans, row, col;
- char Kingdom[23][23];
- void dfs(int i, int j){
- if(i < 0 || i >= row || j < 0 || j >= col)return;
- else if(Kingdom[i][j] == '.')Kingdom[i][j] = 35, ans++;
- else if(Kingdom[i][j] == 35)return;
- dfs(i, j+1);
- dfs(i+1, j);
- dfs(i, j-1);
- dfs(i-1, j);
- }
- int main(){
- int t, cs = 0;
- scanf("%d", &t);
- while(t--){
- scanf("%d %d", &col, &row);
- memset(Kingdom, 0, sizeof(Kingdom));
- for(int i = 0; i < row; i++)scanf("%s", Kingdom[i]);
- for(int i = 0; i < row; i++){
- for(int j = 0; j < col; j++){
- ans = 0;
- if(Kingdom[i][j] == '@'){
- dfs(i, j);break;
- }
- }if(ans)break;
- }
- printf("Case %d: %d\n", ++cs, ans+1);
- }
- return 0;
- }
Saturday, June 6, 2015
LightOJ - 1012 - Guilty Prince
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment