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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Robots at Warehouse(搜索+vector的使用)

發(fā)布時間:2025/4/16 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Robots at Warehouse(搜索+vector的使用) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Vitaly works at the warehouse. The warehouse can be represented as a grid of?n?×?mcells, each of which either is free or is occupied by a container. From every free cell it's possible to reach every other free cell by moving only through the cells sharing a side. Besides that, there are two robots in the warehouse. The robots are located in different free cells.

Vitaly wants to swap the robots. Robots can move only through free cells sharing a side, moreover, they can't be in the same cell at the same time or move through each other. Find out if the swap can be done.

Input

The first line contains two positive integers?n?and?m?(2?≤?n·m?≤?200000)?— the sizes of the warehouse.

Each of the next?n?lines contains?m?characters. The?j-th character of the?i-th line is ?.? if the corresponding cell is free, ?#? if there is a container on it, ?1? if it's occupied by the first robot, and ?2? if it's occupied by the second robot. The characters ?1? and ?2? appear exactly once in these lines.

Output

Output ?YES? (without quotes) if the robots can be swapped, and ?NO? (without quotes) if that can't be done.

Example

Input 5 3

###
#1#
#.#
#2#
### Output NO Input 3 5

#...#
#1.2#
##### Output YES
題意:1和2要進行位置的交換,問你是否能夠成功?
思路:如果在1能夠到達2,并且他們之間的存在有一個點能夠連接三個方向,或者只有一個方向的點的個數(shù)不是2個,則是YES,否則是NO。 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <stack> 5 #include <vector> 6 #include <algorithm> 7 #include<queue> 8 using namespace std; 9 const int maxn=200005; 10 string s[maxn]; 11 typedef pair<int,int>P; 12 P p; 13 queue<P>que; 14 vector<int>vis[maxn]; 15 int n,m,sx,sy,ex,ey; 16 int a[4][2]={{0,1},{0,-1},{1,0},{-1,0}}; 17 void bfs() 18 { 19 for(int i=0; i<n; i++) 20 { 21 vis[i].clear(); 22 for(int j=0; j<m; j++) 23 vis[i].push_back(0); 24 } 25 while(!que.empty()) 26 que.pop(); 27 vis[sx][sy]=1; 28 p.first=sx,p.second=sy; 29 que.push(p); 30 int flag=0; 31 while(!que.empty()) 32 { 33 p=que.front(); 34 que.pop(); 35 int tx=p.first; 36 int ty=p.second; 37 for(int i=0; i<4; i++) 38 { 39 int xx=tx+a[i][0],yy=ty+a[i][1]; 40 if(!(0<=xx&&xx<n&&0<=yy&&yy<m)||s[xx][yy]=='#'||vis[xx][yy]) 41 continue; 42 vis[xx][yy]=1; 43 p.first=xx; 44 p.second=yy; 45 que.push(p); 46 } 47 } 48 } 49 int main() 50 { 51 while(~scanf("%d%d",&n,&m)) 52 { 53 for(int i=0; i<n; i++) 54 { 55 cin>>s[i]; 56 for(int j=0; j<m; j++) 57 { 58 if(s[i][j]=='1') 59 { 60 sx=i,sy=j; 61 } 62 else if(s[i][j]=='2') 63 { 64 ex=i,ey=j; 65 } 66 } 67 } 68 bfs(); 69 if(!vis[ex][ey]) 70 { 71 printf("NO\n"); 72 continue; 73 } 74 int flag=0,ans=0,cnt; 75 for(int i=0;i<n;i++) 76 { 77 for(int j=0;j<m;j++) 78 { 79 if(flag) 80 break; 81 cnt=0; 82 if(vis[i][j]) 83 { 84 for(int k=0;k<4;k++) 85 { 86 if(!(0<=i+a[k][0]&&i+a[k][0]<n&&0<=j+a[k][1]&&j+a[k][1]<m)||s[i+a[k][0]][j+a[k][1]]=='#') 87 continue; 88 if(vis[i+a[k][0]][j+a[k][1]]) 89 cnt++; 90 } 91 if(cnt>2) 92 { 93 flag=1; 94 printf("YES\n"); 95 break; 96 } 97 if(cnt==1) ans++; 98 } 99 } 100 if(flag) 101 break; 102 } 103 if(flag==0) 104 { 105 if(ans==2) printf("NO\n"); 106 else printf("YES\n"); 107 } 108 } 109 return 0; 110 } View Code

知識點:

由于n,m<=200000,所以無法定義flag數(shù)組進行標記。使用vector容器能夠很好的解決這一問題。

轉(zhuǎn)載于:https://www.cnblogs.com/wang-ya-wei/p/6894941.html

總結(jié)

以上是生活随笔為你收集整理的Robots at Warehouse(搜索+vector的使用)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 一本之道久久 | 麻豆av电影网 | 99精品久久精品一区二区 | 天堂成人在线视频 | 免费在线视频观看 | 日本人妻丰满熟妇久久久久久 | 禁片天堂 | 国产成人精品在线观看 | 麻豆观看| 日韩中文字幕免费在线观看 | 在线97视频 | 无码aⅴ精品一区二区三区浪潮 | 梦梦电影免费高清在线观看 | 一级久久久久久 | 日p视频在线观看 | 欧美在线视频一区二区 | 王者后宫yin肉h文催眠 | 已婚少妇美妙人妻系列 | 美足av电影 | 成人激情综合 | 黄色一级片 | 人体私拍套图hdxxxx | 欧美日韩国产三区 | 麻豆精品在线观看 | 美女被啪啪 | 黑人av | www.色综合.com| 狠狠综合一区 | 成人av在线一区二区 | 成人免费毛片嘿嘿连载视频 | 欧美理论视频 | 亚洲精品成人在线视频 | 欧美人与zoxxxx另类 | 国产成年无码久久久久毛片 | 日韩黄色av网站 | 色日韩 | 天天撸夜夜操 | 精久久久久 | 日韩第四页 | 911看片| 男生坤坤放进女生坤坤里 | 亚洲色图综合在线 | 欧美精品亚洲一区 | 国产成人精品一区二区无码呦 | 免费黄网在线看 | 黄色a级在线观看 | 亚洲精品高清视频在线观看 | 少妇被又大又粗又爽毛片久久黑人 | 91国内在线视频 | 欧美一级在线 | 国产精品久久久久9999 | 国产中出| 四虎永久免费 | 中文字幕免费在线观看 | 男人操女人动态图 | 成人欧美一区二区三区黑人孕妇 | 欧美一区二区视频免费观看 | 亚洲国产欧美日韩在线 | 国产免费无码一区二区视频 | 国产精品区在线 | 午夜免费大片 | 色婷婷av一区二区三区之e本道 | 亚洲女同志亚洲女同女播放 | 韩国三级av| www在线| 国产一级片视频 | 日韩成人三级 | 岛国av免费 | 91精品国产一区 | 天海翼一区 | 亚洲午夜一区二区 | 91国内产香蕉 | 日韩福利片 | 日韩在线观看你懂的 | 国产av无码专区亚洲a∨毛片 | 91在线小视频 | 人妻少妇偷人精品无码 | 久久爰 | 99热这里是精品 | 97se.com | 一级久久 | av网址观看 | 999在线观看视频 | 亚洲视频大全 | 精品伊人 | 亚洲精品嫩草 | 三级av在线播放 | 国产日产亚洲系列最新 | 天堂在线观看中文字幕 | 不卡av一区二区 | 久热精品视频在线 | 日本三级免费看 | 国产91页 | 国产一线二线三线在线观看 | 91视频在线| 美女视频久久久 | 女人洗澡一级特黄毛片 | 男女无套免费视频网站动漫 | 强迫凌虐淫辱の牝奴在线观看 |