日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #301 (Div. 2) B. School Marks

發布時間:2025/3/13 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #301 (Div. 2) B. School Marks 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

其實是很水的一道bfs題,昨晚比賽的時候沒看清題意,漏了一個條件。

1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<cmath> 5 #include<algorithm> 6 #include<set> 7 #include<map> 8 #include<queue> 9 #include<stack> 10 #include<string> 11 #include<vector> 12 #define maxn 13 #define INF 1000000000 14 using namespace std; 15 int vist[510][510]; 16 char str[510][510]; 17 int dirx[]={-1,0,1,0}; 18 int diry[]={0,1,0,-1}; 19 int m,n,stx,sty,edx,edy; 20 int judge(int x,int y) 21 { 22 if(x>=0&&x<n&&y>=0&&y<m) 23 return 1; 24 return 0; 25 } 26 int bfs() 27 { 28 queue<int> q; 29 stx--; 30 sty--;edx--;edy--; 31 int num=stx*m+sty; 32 q.push(num); 33 //vist[stx][sty]--;就改的這個地方,因為起點和終點有可能相同 34 while(!q.empty()) 35 { 36 num=q.front(); 37 //printf("%d==\n",num); 38 q.pop(); 39 int xx=num/m; 40 int yy=num%m; 41 42 for(int i=0;i<4;i++) 43 { 44 int newx=xx+dirx[i]; 45 int newy=yy+diry[i]; 46 if(newx==edx&&newy==edy&&vist[newx][newy]==0) 47 return 1; 48 if(judge(newx,newy)&&vist[newx][newy]>0) 49 { 50 q.push(newx*m+newy); 51 vist[newx][newy]--; 52 } 53 } 54 } 55 //printf("==\n"); 56 return 0; 57 58 } 59 int main() 60 { 61 scanf("%d %d",&n,&m); 62 for(int i=0;i<n;i++) 63 scanf("%s",str[i]); 64 scanf("%d %d",&stx,&sty); 65 scanf("%d %d",&edx,&edy); 66 for(int i=0;i<n;i++) 67 { 68 for(int j=0;j<m;j++) 69 { 70 if(str[i][j]=='X') 71 vist[i][j]=0; 72 else 73 vist[i][j]=1; 74 } 75 } 76 if(bfs()) 77 printf("YES\n"); 78 else 79 printf("NO\n"); 80 return 0; 81 }

?

轉載于:https://www.cnblogs.com/tsw123/p/4470387.html

總結

以上是生活随笔為你收集整理的Codeforces Round #301 (Div. 2) B. School Marks的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。