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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

【CodeForces - 616C】The Labyrinth(bfs,并查集,STLset)

發布時間:2023/12/10 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 616C】The Labyrinth(bfs,并查集,STLset) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

求每個*能夠到達的格子數量,只有.可以走(四個方向擴展),結果mod 10,替換 * 后輸出。

Input

The first line contains two integers?n,?m?(1?≤?n,?m?≤?1000) — the number of rows and columns in the field.

Each of the next?n?lines contains?m?symbols: "." for empty cells, "*" for impassable cells.

Output

Print the answer as a matrix as described above. See the examples to precise the format of the output.

Examples

Input

3 3 *.* .*. *.*

Output

3.3 .5. 3.3

Input

4 5 **..* ..*** .*.*. *.*.*

Output

46..3 ..732 .6.4. 5.4.3

Note

In first example, if we imagine that the central cell is empty then it will be included to component of size?5?(cross). If any of the corner cell will be empty then it will be included to component of size?3?(corner).

解題報告:

? ?直接對每個'.'進行搜索看連通塊,然后對每一個'*'直接求答案就行了,注意不要算重復,所以需要set去判重。(因為有可能四個方向屬于同一個聯通塊,所以不判重就會加四次)

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair using namespace std; const int MAX = 1000 + 5; char maze[MAX][MAX]; int ans[MAX][MAX]; bool vis[MAX][MAX]; int f[MAX*MAX]; int num[MAX*MAX]; int n,m; int nx[4] = {0,1,0,-1}; int ny[4] = {1,0,-1,0}; int getf(int v) {return v == f[v] ? v : f[v] = getf(f[v]); } void merge(int u,int v) {int t1 = getf(u);int t2 = getf(v);f[t2] = t1; } int get(int x,int y) {return (x-1)*m +y; } void go(int x,int y) {for(int k = 0; k<4; k++) {int tx = x + nx[k];int ty = y + ny[k];if(tx < 1 || tx > n || ty < 1 || ty > m) continue;if(maze[tx][ty] == '*' || vis[tx][ty]) continue;merge(get(x,y),get(tx,ty));vis[tx][ty] = 1;go(tx,ty);} } int main() {cin>>n>>m;for(int i = 0; i<=n*m; i++) {f[i] = i;}for(int i = 1; i<=n; i++) {scanf("%s",maze[i]+1);}for(int i = 1; i<=n; i++) {for(int j = 1; j<=m; j++) {if(maze[i][j] == '.' && vis[i][j] == 0) {vis[i][j] = 1;//別忘這步!!雖然這題不會WA但是不寫是錯的。go(i,j);} }}for(int i = 1; i<=n; i++) {for(int j = 1; j<=m; j++) {if(maze[i][j] == '*') continue;num[getf(get(i,j))]++;}}for(int i = 1; i<=n; i++) {for(int j = 1; j<=m; j++) {if(maze[i][j] == '.') ans[i][j] = '.';else {int cnt = 0;set<int> ss;for(int k = 0; k<4; k++) {int tx = i + nx[k];int ty = j + ny[k];if(maze[tx][ty] == '*')continue;if(tx < 1 || tx > n || ty < 1 || ty > m) continue;ss.insert(getf(get(tx,ty)));}auto it = ss.begin();for(;it!=ss.end();++it) cnt += num[*it];ans[i][j] = cnt;}}}for(int i = 1; i<=n; i++) {for(int j = 1; j<=m; j++) {if(maze[i][j] == '.') printf(".");else printf("%d",(ans[i][j]+1)%10);}puts("");}return 0 ; }

?

總結

以上是生活随笔為你收集整理的【CodeForces - 616C】The Labyrinth(bfs,并查集,STLset)的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 国产视频二 | 337p日本欧洲亚洲鲁鲁 | 成人午夜黄色 | 四虎国产视频 | 在线看黄色片 | 九色91在线| 国产福利视频网站 | 亚洲av无码专区首页 | 日韩美女少妇 | 午夜美女福利 | 亚洲国产精品久久久久久6q | 91精品国产一区二区三竹菊影视 | 久久久久人妻一道无码AV | 亚洲国产精品va在线 | 九色网址 | 欧美xx孕妇 | 欧美手机在线视频 | 狠狠操狠狠摸 | 中文字幕+乱码+中文乱码91 | 亚洲在线视频观看 | 91婷婷射| 中文字幕在线观看第二页 | 亚色影库 | 国产中文在线观看 | 天天爽夜夜爽夜夜爽精品视频 | 少女与动物高清版在线观看 | 午夜剧场91 | 99久久久| 伊人手机在线视频 | 亚洲激情网址 | 国产精品久久免费视频 | 香蕉久久一区二区三区 | 国产精品36p | 亚洲综合伊人久久 | 亚洲熟女乱色综合亚洲av | 大尺度av| 免费的一级片 | caoporn成人| 久草加勒比 | 白嫩情侣偷拍呻吟刺激 | 精品久久久国产 | 久久久99精品国产一区二区三区 | 在线观看国产精品入口男同 | 亚洲性色图 | 青青草国产精品 | 少妇又紧又深又湿又爽视频 | 久久久无码精品亚洲无少妇 | 天天干夜夜欢 | 一本大道久久a久久精二百 琪琪色在线视频 | 日本三级大片 | 激情黄色av | 四虎精品一区二区三区 | 综合精品视频 | 日韩欧美毛片 | 免费中文字幕在线观看 | 久久午夜夜伦鲁鲁片无码免费 | 精品无码国产一区二区三区av | 午夜日韩视频 | 天天躁日日躁狠狠躁喷水 | 波多野结衣免费在线视频 | 亚洲综合免费观看高清完整版在线 | bangbros性欧美18 | 少妇又紧又色 | 91黄版| 免费成人深夜夜行网站视频 | 性高湖久久久久久久久aaaaa | 欧美乱色| 国产精品三级在线 | 成人免费看片'在线观看 | 久久精品噜噜噜成人88aⅴ | 国产乱女淫av麻豆国产 | 中文字幕丰满人伦在线 | 日韩亚洲欧美在线 | 曰本不卡视频 | 狠狠噜噜| 国产精品免费一区二区区 | av特黄| 国产午夜精品理论片在线 | 国产精品视频成人 | av老司机在线播放 | 九九精品影院 | 韩国成人在线视频 | 午夜精品久久久久久久久久蜜桃 | 无码人妻aⅴ一区二区三区有奶水 | 免费看美女隐私网站 | 午夜av在线播放 | 欧美a√在线 | 夜夜夜网站 | 精品人妻一区二区乱码 | 国产一级黄色大片 | 日韩三级视频在线 | 无码少妇一区二区三区 | 91视频国产一区 | 华丽的外出在线观看 | 国产精品无码天天爽视频 | www.操com| 日韩av免费播放 | 波多野吉衣久久 | 夜夜摸夜夜爽 |