标签:space n+2 rip text main direction else nsis art
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 41222 | Accepted: 22338 |
Description
Input
Output
Sample Input
6 9
....#.
.....#
......
......
......
......
......
#@...#
.#..#.
11 9
.#.........
.#.#######.
.#.#.....#.
.#.#.###.#.
.#.#..@#.#.
.#.#####.#.
.#.......#.
.#########.
...........
11 6
..#..#..#..
..#..#..#..
..#..#..###
..#..#..#@.
..#..#..#..
..#..#..#..
7 7
..#.#..
..#.#..
###.###
...@...
###.###
..#.#..
..#.#..
0 0
Sample Output
45
59
6
13
Source
#include<queue> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int map[21][21]; int w,h,sx,sy,ans; int dx[4]={1,-1,0,0}; int dy[4]={0,0,1,-1}; struct nond{ int x,y; }; int main(){ while(scanf("%d%d",&w,&h)&&w!=0&&h!=0){ swap(w,h); for(int i=1;i<=w;i++) for(int j=1;j<=h;j++){ char x;cin>>x; if(x==‘.‘) map[i][j]=0; else if(x==‘#‘) map[i][j]=1; else if(x==‘@‘){ sx=i;sy=j;map[i][j]=0; } } queue<nond>que;ans=1; nond tmp;tmp.x=sx;tmp.y=sy; que.push(tmp);map[sx][sy]=1; while(!que.empty()){ nond now=que.front(); que.pop(); for(int i=0;i<4;i++){ int cx=dx[i]+now.x; int cy=dy[i]+now.y; if(cx>=1&&cx<=w&&cy>=1&&cy<=h&&!map[cx][cy]){ map[cx][cy]=1; nond mid;mid.x=cx;mid.y=cy; que.push(mid);ans++; //cout<<cx<<" "<<cy<<endl; } } } cout<<ans<<endl; } }
标签:space n+2 rip text main direction else nsis art
原文地址:https://www.cnblogs.com/cangT-Tlan/p/8970323.html