标签:des style http color strong os
Description
Input
Output
Sample Input
6 9 ....#. .....# ...... ...... ...... ...... ...... #@...# .#..#. 11 9 .#......... .#.#######. .#.#.....#. .#.#.###.#. .#.#..@#.#. .#.#####.#. .#.......#. .#########. ........... 11 6 ..#..#..#.. ..#..#..#.. ..#..#..### ..#..#..#@. ..#..#..#.. ..#..#..#.. 7 7 ..#.#.. ..#.#.. ###.### ...@... ###.### ..#.#.. ..#.#.. 0 0
Sample Output
45 59 6 13
#include<iostream> #include<cstring> using namespace std; int b,c,k,i,s,x,y,n; char a[21][21]; int sousuo(int x,int y,int a1,int b) { int n=0; if(x>0) if(a[x-1][y]=='.') {n++;a[x-1][y]='a';n=n+sousuo(x-1,y,a1,b);} if(y>0) if(a[x][y-1]=='.') {n++;a[x][y-1]='a';n=n+sousuo(x,y-1,a1,b);} if(x<a1) if(a[x+1][y]=='.') {n++;a[x+1][y]='a';n=n+sousuo(x+1,y,a1,b);} if(y<b) if(a[x][y+1]=='.') {n++;a[x][y+1]='a';n=n+sousuo(x,y+1,a1,b);} return n; } int main() { int j; while(cin>>k>>s&&k) { memset(a,'q',sizeof(a)); for(i=0;i<s;i++) for(j=0;j<k;j++) { cin>>a[i][j]; if(a[i][j]=='@') x=i,y=j; } n=sousuo(x,y,s,k); cout<<++n<<endl; } return 0; }
A - Red and Black(3.2.1)(搜索),布布扣,bubuko.com
标签:des style http color strong os
原文地址:http://blog.csdn.net/rememberautumn/article/details/37766973