// 额...很无聊做一些super大水题... 无聊逛网站发现今年acm final 在 Orlando<奥兰多> 进行 ,真是爽阿, 我等只能弱势围观,
   祝愿国内的众多神犇取得好成绩.
1 Source Code
2
3 Problem: 1979 User: eth1
4 Memory: 736K Time: 32MS
5 Language: G++ Result: Accepted
6
7 Source Code
8 #include <iostream>
9 #include <algorithm>
10 #include <cstring>
11 #include <cmath>
12 #include <queue>
13 using namespace std;
14 int d[4][2]={-1,0,1,0,0,-1,0,1};
15 int ans,n,m,vis[21][21];
16 char f[21][21];
17 struct node{int x,y;};
18 queue<node> q;
19 bool check(node a)
20 {
21 if(a.x<0 || a.x>=n || a.y<0 || a.y>=m || f[a.x][a.y]=='#' || vis[a.x][a.y])
22 return 0;
23 return 1;
24 }
25 void solve()
26 {
27 while(!q.empty())
28 {
29 node a = q.front();
30 q.pop();
31 ans++;
32 for(int i=0;i<4;i++)
33 {
34 node tem = a;
35 tem.x += d[i][0];
36 tem.y += d[i][1];
37 if(check(tem))
38 {
39 vis[tem.x][tem.y]=1;
40 q.push(tem);
41 }
42 }
43 }
44 }
45 int main()
46 {
47 while(cin>>m>>n && n+m)
48 {
49 int x,y;
50 memset(vis,0,sizeof(vis));
51 for(int i=0;i<n;i++)
52 {
53 cin>>f[i];
54 for(int j=0;j<m;j++)
55 {
56 if(f[i][j]=='@')
57 {
58 x=i;y=j;
59 }
60 }
61 }
62 vis[x][y]=1;
63 node a;
64 a.x=x;a.y=y;
65 q.push(a);
66 ans=0;
67 solve();
68 cout<<ans<<endl;
69 }
70 return 0;
71 }
 posted on 2011-05-14 20:57  eth0  阅读(161)  评论(0)    收藏  举报