Skip to content

Commit

Permalink
Add some basic problems on lightoj.com
Browse files Browse the repository at this point in the history
  • Loading branch information
tranchitam committed Jun 17, 2015
1 parent e72d5cb commit 2b35fee
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions lightoj.com/1012.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>

#define MAX 20

using namespace std;

void solve(char s[][MAX], int w, int h, int sx, int sy, int &m){
if(s[sx][sy] == '@' || s[sx][sy] == '.'){
s[sx][sy] = '#';
m++;
solve(s, w, h, max(sx - 1, 0), sy, m);
solve(s, w, h, min(sx + 1, h - 1), sy, m);
solve(s, w, h, sx, max(sy - 1, 0), m);
solve(s, w, h, sx, min(sy + 1, w - 1), m);
}
}

int main(){
int t, w, h;
scanf("%d", &t);
for(int i = 1; i <= t; i++){
scanf("%d %d", &w, &h);
char s[h][MAX];
int sx, sy;
for(int j = 0; j < h; j++){
scanf("%s", &s[j]);
for(int jj = 0; jj < strlen(s[j]); jj++){
if(s[j][jj] == '@'){
sx = j;
sy = jj;
}
}
}
int m = 0;
solve(s, w, h, sx, sy, m);
printf("Case %d: %d\n", i, m);
}
}

0 comments on commit 2b35fee

Please sign in to comment.