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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

sdut 2152:Balloons(第一届山东省省赛原题,DFS搜索)

發(fā)布時間:2024/1/17 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 sdut 2152:Balloons(第一届山东省省赛原题,DFS搜索) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Balloons

Time Limit: 1000MS Memory limit: 65536K

題目描述

Both Saya and Kudo like balloons. One day, they heard that in the central park, there will be thousands of people fly balloons to pattern a big image.
They were very interested about this event, and also curious about the image.
Since there are too many balloons, it is very hard for them to compute anything they need. Can you help them?
You can assume that the image is an N*N matrix, while each element can be either balloons or blank.
Suppose element A and element B are both balloons. They are connected if:
i) They are adjacent;
ii) There is a list of element C1, C2, … , Cn, while A and C1 are connected, C1 and C2 are connected …Cn and B are connected.
And a connected block means that every pair of elements in the block is connected, while any element in the block is not connected with any element out of the block.
To Saya, element A(xa,ya)and B(xb,yb) is adjacent if |xa-xb| + |ya-yb|??1?
But to Kudo, element A(xa,ya) and element B (xb,yb) is adjacent if |xa-xb|≤1 and |ya-yb|1
They want to know that there’s how many connected blocks with there own definition of adjacent?

輸入

The input consists of several test cases.
The first line of input in each test case contains one integer N (0<N100), which represents the size of the matrix.
Each of the next N lines contains a string whose length is N, represents the elements of the matrix. The string only consists of 0 and 1, while 0 represents a block and 1represents balloons.
The last case is followed by a line containing one zero.

輸出

?For each case, print the case number (1, 2 …) and the connected block’s numbers with Saya and Kudo’s definition. Your output format should imitate the sample output. Print a blank line after each test case.

示例輸入

5 11001 00100 11111 11010 100100

示例輸出

Case 1: 3 2

提示

來源

2010年山東省第一屆ACM大學(xué)生程序設(shè)計競賽

?

  DFS搜索,求連通分量的個數(shù)。需要注意的是第一個只能是4個方向,而第二個可以有8個方向,即可以斜著走。

  代碼:

1 #include <iostream> 2 #include <stdio.h> 3 using namespace std; 4 int n; 5 int dx[4] = {0,-1,0,1}; 6 int dy[4] = {-1,0,1,0}; 7 int Dx[8] = {0,-1,-1,-1,0,1,1,1}; 8 int Dy[8] = {-1,-1,0,1,1,1,0,-1}; 9 10 bool judge(char a[101][101],int x,int y) 11 { 12 if(x<0 || y<0 || x>=n || y>=n) 13 return 1; 14 if(a[x][y]!='1') 15 return 1; 16 return 0; 17 } 18 void dfs1(char a[][101],int x,int y) 19 { 20 a[x][y] = '0'; 21 for(int i=0;i<4;i++){ 22 int cx = x+dx[i]; 23 int cy = y+dy[i]; 24 if(judge(a,cx,cy)) 25 continue; 26 dfs1(a,cx,cy); 27 } 28 } 29 void dfs2(char a[][101],int x,int y) 30 { 31 a[x][y] = '0'; 32 for(int i=0;i<8;i++){ 33 int cx = x+Dx[i]; 34 int cy = y+Dy[i]; 35 if(judge(a,cx,cy)) 36 continue; 37 dfs2(a,cx,cy); 38 } 39 } 40 int main() 41 { 42 int Count=1; 43 while(cin>>n){ 44 if(n==0) break; 45 int num1 = 0,num2 = 0; 46 char a[101][101]; 47 char b[101][101]; 48 for(int i=0;i<n;i++){ 49 cin>>a[i]; 50 } 51 for(int i=0;i<n;i++) 52 for(int j=0;j<n;j++) 53 b[i][j]=a[i][j]; 54 int i,j; 55 for(i=0;i<n;i++) 56 for(j=0;j<n;j++){ 57 if(a[i][j]=='1'){ 58 num1++; 59 dfs1(a,i,j); 60 } 61 } 62 for(i=0;i<n;i++) 63 for(j=0;j<n;j++){ 64 if(b[i][j]=='1'){ 65 num2++; 66 dfs2(b,i,j); 67 } 68 } 69 cout<<"Case "<<Count++<<": "<<num1<<' '<<num2<<endl<<endl; 70 } 71 return 0; 72 }

?

Freecode : www.cnblogs.com/yym2013

轉(zhuǎn)載于:https://www.cnblogs.com/yym2013/p/3662190.html

總結(jié)

以上是生活随笔為你收集整理的sdut 2152:Balloons(第一届山东省省赛原题,DFS搜索)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 超碰在线亚洲 | 午夜性刺激免费视频 | 欧美一级片在线 | 久操视频网站 | www.成人在线 | 国产波霸爆乳一区二区 | 黄视频国产 | 色久av| 国产精品久久久久久久久久久久久久久久久 | 亚洲一区免费视频 | 日韩精品乱码 | 欧美亚洲在线视频 | 91色在线观看 | 97少妇| 蜜桃无码一区二区三区 | 午夜视频久久 | 精品一级少妇久久久久久久 | 午夜国产一区二区 | 中文字幕亚洲欧美 | 中文字幕第二页 | 成熟了的熟妇毛茸茸 | 亚洲一区不卡 | 美女被啪羞羞粉色视频 | 国产熟妇另类久久久久 | 99精品国产免费 | 波多野结衣视频播放 | 久草成人在线视频 | 欧美日韩一级黄色片 | 午夜男人网 | 成人伊人 | 国产精品久久久久久久久免费桃花 | 色人阁在线视频 | 色哟哟日韩精品 | 福利片在线看 | 在线免费观看a视频 | 国产在线播放网站 | 欧洲做受高潮欧美裸体艺术 | 成人免费视频国产在线观看 | 日韩av综合 | 黄色一级小视频 | 日韩xxxxxxxxx| 风流少妇 | 日本裸体网站 | 伊人久久艹 | 激情影音 | 国产裸体永久免费无遮挡 | 岛国裸体写真hd在线 | 亚洲色图21p | 色欧洲| 日本在线视频www | 色xxxxxx| 嫩草精品 | 日本少妇在线 | 天天摸天天操天天干 | av在线免费观看一区 | 一区二区免费在线播放 | 美女100%露胸无遮挡 | 日本a天堂 | 2018天天弄 | 久久久精品视频一区 | 免费在线不卡av | 亚洲欧洲久久 | 毛片的网址 | 精品少妇一区二区 | 97精品人人妻人人 | 国产精自产拍久久久久久蜜 | 成人免费视频网站在线观看 | 久久久久99精品成人片三人毛片 | 久久久久久久香蕉 | 亚洲国产精品久久人人爱 | 茄子视频色 | 成年视频在线观看 | 欧美天天射 | 一级免费视频 | 先锋影音亚洲 | 中文字幕久久久久久久 | 日本三级黄色录像 | 国产精品热久久 | 免费高清欧美大片在线观看 | 国产毛片99| 欧美色图网站 | 久草国产在线视频 | 日本色中色 | 午夜国产 | www视频免费观看 | 久久这里只有精品6 | 成av人在线观看 | 中文字幕av久久 | 一本久久道| 高h视频在线免费观看 | 中国大陆高清aⅴ毛片 | 最新久久 | 97香蕉久久夜色精品国产 | 欧美一级片免费在线观看 | 欧美国产精品一区二区三区 | 农村黄色片 | 国产原创麻豆 | 国产不卡视频一区二区三区 | 欧美成人h版 |