标签:
input | output |
---|---|
5 ..... ...## ..#.. ..### ..... |
198 |
#include <iostream> #include <cstring> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <time.h> #include <string> #include <map> #include <stack> #include <vector> #include <set> #include <queue> #define inf 0x3f3f3f3f #define mod 10000 typedef long long ll; using namespace std; const int N=35; const int M=100005; int n,m,k,ans=0,t,cnt; int vis[N][N]; int d[4][2]={0,1,1,0,-1,0,0,-1}; char w[N][N]; struct man{ int x,y; }; void bfs(int x,int y) { queue<man>q; vis[x][y]=1; man s;s.x=x;s.y=y; q.push(s); while(!q.empty()){ man t=q.front();q.pop(); for(int i=0;i<4;i++){ int xx=t.x+d[i][0]; int yy=t.y+d[i][1]; if(xx<0||xx>=n||yy<0||yy>=n)ans++; else if(w[xx][yy]==‘#‘)ans++; else if(!vis[xx][yy]){ man k;k.x=xx;k.y=yy; q.push(k); vis[xx][yy]=1; } } } } int main() { scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%s",w[i]); } bfs(0,0); if(!vis[n-1][n-1])bfs(n-1,n-1); printf("%d\n",(ans-4)*9); return 0; }
标签:
原文地址:http://www.cnblogs.com/jianrenfang/p/5874372.html