Red and Black&&http://acm.hdu.edu.cn/showproblem.php?pid=1312
2012-07-25 13:17
513 查看
DFS不解释。。
#include<iostream> #include<string.h> #include<string> #include<cstdio> #define N 50 using namespace std; int n,m; char map ; int sum; void dfs(int x,int y) { if(map[x+1][y]=='.') {sum++;map[x+1][y]='#';dfs(x+1,y);} if(map[x-1][y]=='.') {sum++;map[x-1][y]='#';dfs(x-1,y);} if(map[x][y-1]=='.') {sum++;map[x][y-1]='#';dfs(x,y-1);} if(map[x][y+1]=='.') {sum++;map[x][y+1]='#';dfs(x,y+1);} } int main() { while(cin>>m>>n) { if(!n&&!m) break; memset(map,'\0',sizeof(map)); sum=1; int a,b; for(int i=0;i<n;++i) { cin>>map[i]; for(int j=0;j<m;++j) if(map[i][j]=='@') a=i,b=j; } map[a][b]='#'; dfs(a,b); cout<<sum<<endl; }return 0; }
相关文章推荐
- 最小路径覆盖&&http://acm.hdu.edu.cn/showproblem.php?pid=4160
- 完数 &&http://acm.hdu.edu.cn/showproblem.php?pid=1406
- Text Reverse&&http://acm.hdu.edu.cn/showproblem.php?pid=1062
- HDU Today&&http://acm.hdu.edu.cn/showproblem.php?pid=2112
- http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?cid=963&pid=1019&ojid=1
- http://acm.hdu.edu.cn/showproblem.php?pid=1059&&多重背包
- A C&&http://acm.hdu.edu.cn/showproblem.php?pid=1570
- find the safest road&&http://acm.hdu.edu.cn/showproblem.php?pid=1596
- Trouble&&http://acm.hdu.edu.cn/showproblem.php?pid=4334
- Quoit Design&&http://acm.hdu.edu.cn/showproblem.php?pid=1007
- http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1004&ojid=1&cid=6866&hide=1&problem=Pro
- 找规律。。&&http://acm.hdu.edu.cn/showproblem.php?pid=1097
- To The Max &&http://acm.hdu.edu.cn/showproblem.php?pid=1081
- Clairewd’s message&&http://acm.hdu.edu.cn/showproblem.php?pid=4300
- Buy the Ticket&&http://acm.hdu.edu.cn/showproblem.php?pid=1133
- A + B Problem II &&http://acm.hdu.edu.cn/showproblem.php?pid=1002
- Number Sequence&&http://acm.hdu.edu.cn/showproblem.php?pid=1005
- I NEED A OFFER! &&http://acm.hdu.edu.cn/showproblem.php?pid=1203
- http://acm.hdu.edu.cn/showproblem.php?pid=2795&&线段树之求最小区间端点值
- Holedox Eating &&http://acm.hdu.edu.cn/showproblem.php?pid=4302