标签:des style blog http color os io strong 文件
1 #include<cstdio> 2 #include<cmath> 3 #include<queue> 4 #include<cstring> 5 #include<stdlib.h> 6 #include<algorithm> 7 using namespace std; 8 const int MAXN=1000+10; 9 const int INF=-0x3f3f3f3f; 10 struct node 11 { 12 int x,y; 13 int step; 14 }p; 15 int starx,stary,ans; 16 int n,m,x,y,ok; 17 int vis[MAXN][MAXN]; 18 int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; 19 void BFS() 20 { 21 memset(vis,0,sizeof(vis)); 22 queue<node> Q; 23 ans=0; 24 p.x=starx; 25 p.y=stary; 26 p.step=0; 27 Q.push(p); 28 while(!Q.empty()) 29 { 30 node now,next; 31 now=Q.front(); 32 Q.pop(); 33 for(int i=0;i<4;i++) 34 { 35 next.x=now.x+dir[i][0]; 36 next.y=now.y+dir[i][1]; 37 next.step=now.step+1; 38 if(0<=next.x && next.x<n && 0<=next.y && next.y<m && !vis[next.x][next.y] && next.step<=ok) 39 { 40 vis[next.x][next.y]=1; 41 ans++; 42 Q.push(next); 43 } 44 } 45 } 46 } 47 int main() 48 { 49 //freopen("in.txt","r",stdin); 50 scanf("%d %d %d %d %d",&n,&m,&x,&y,&ok); 51 starx=x-1; 52 stary=y-1; 53 BFS(); 54 printf("%d\n",ans); 55 return 0; 56 }
标签:des style blog http color os io strong 文件
原文地址:http://www.cnblogs.com/clliff/p/3936684.html