Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
菜鸟的代码#include<stdio.h> #include<string.h> #include<queue> #include<algorithm> using namespace std; struct P { int x,y; }; char s[25][25]; int y[8]={-1,0,1,-1,1,-1,0,1}; int x[8]={-1,-1,-1,0,0,1,1,1}; int a[4]={-1,0,0,1}; int b[4]={0,-1,1,0}; bool vis[25][25]; int r,c,X,Y; int ans; void bfs() { queue<P>q; P p; p.x=X-1; p.y=Y-1; q.push(p); vis[p.x][p.y]=1; while(q.size()) { P t=q.front(); //printf("%d %d\n",t.x,t.y); q.pop(); for(int i=0;i<8;i++) { P v; v.x=t.x+x[i]; v.y=t.y+y[i]; if(v.x>=0&&v.x<r&&v.y>=0&&v.y<c&&s[v.x][v.y]=='X'&&vis[v.x][v.y]==0) { q.push(v); vis[v.x][v.y]=1; } } int sum=4; for(int i=0;i<4;i++) { int sx=t.x+a[i]; int sy=t.y+b[i]; if(sx>=0&&sx<r&&sy>=0&&sy<c&&s[sx][sy]=='X') sum--; } //printf("%d ",sum); ans+=sum; } } int main() { while(scanf("%d %d %d %d",&r,&c,&X,&Y)!=EOF) { getchar(); if(r==0&&c==0&&X==0&&Y==0) break; else { ans=0; memset(vis,0,sizeof(vis)); memset(s,'\0',sizeof(s)); for(int i=0;i<r;i++) scanf("%s",s[i]); bfs(); printf("%d\n",ans); } }return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator