亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

ACM 深搜&廣搜 Counting Sheep&Space Exploration

2019-11-14 11:03:05
字體:
來源:轉載
供稿:網友

數羊/牛/石油群類的,就是分堆的搜索。

這里考慮用深搜or廣搜,憑借題目給的地圖范圍,范圍大的用廣搜。

TOJ 2799 Counting Sheep

A while ago I had trouble sleeping. I used to lie awake, staring at the ceiling, for hours and hours. Then one day my grandmother suggested I tried counting sheep after I'd gone to bed. As always when my grandmother suggests things, I decided to try it out. The only PRoblem was, there were no sheep around to be counted when I went to bed.

Creative as I am, that wasn't going to stop me. I sat down and wrote a computer program that made a grid of characters, where # represents a sheep, while . is grass (or whatever you like, just not sheep). To make the counting a little more interesting, I also decided I wanted to count flocks of sheep instead of single sheep. Two sheep are in the same flock if they share a common side (up, down, right or left). Also, if sheep A is in the same flock as sheep B, and sheep B is in the same flock as sheep C, then sheeps A and C are in the same flock.Now, I've got a new problem. Though counting these sheep actually helps me fall asleep, I find that it is extremely boring. To solve this, I've decided I need another computer program that does the counting for me. Then I'll be able to just start both these programs before I go to bed, and I'll sleep tight until the morning without any disturbances. I need you to write this program for me.

輸入

The first line of input contains a single number T, the number of test cases to follow.Each test case begins with a line containing two numbers, H and W, the height and width of the sheep grid. Then follows H lines, each containing W characters (either # or .), describing that part of the grid.

輸出

For each test case, output a line containing a single number, the amount of sheep flock son that grid according to the rules stated in the problem description.Notes and Constraints0 < T <= 1000 < H,W <= 100

樣例輸入

樣例輸出

題目意思:數羊群,上下左右四個方向,相連的即為一個羊群。

這題用深搜就可以了,比較簡單。

#include <stdio.h>int a,b,s;char m[101][101];	int dir[4][2]={1,0,0,1,-1,0,0,-1};void dfs(int x,int y){  	m[x][y]='.';	int i,xx,yy;   for(i=0;i<4;i++)   {   	xx=x+dir[i][0];   	yy=y+dir[i][1];   	if(xx>=0&&xx<a&&yy>=0&&yy<b&&m[xx][yy]=='#')    dfs(xx,yy);   }	}int main()//2777{	int i,j,u,w,t;	scanf("%d",&t);	while(t--)	{   scanf("%d%d",&a,&b);	    s=0;		if(a==0&&b==0)break;		for(i=0;i<a;i++)		scanf("%s",m[i]);					for(i=0;i<a;i++)		{			for(j=0;j<b;j++)			{				if(m[i][j]=='#')				{dfs(i,j);				s++;}			}		} 		printf("%d/n",s);		}}

TOJ 3834 Space Exploration

描述

Farmer John's cows have finally blasted off from earth and are now floating around space in their Moocraft. The cows want to reachtheir fiery kin on Jupiter's moon of Io, but to do this they must first navigate through the dangerous asteroid belt.

Bessie is piloting the craft through this treacherous N x N (1 <= N <= 1,000) sector of space. Asteroids in this sector comprise somenumber of 1 x 1 squares of space-rock connected along their edges (two squares sharing only a corner count as two distinct asteroids).Please help Bessie maneuver through the field by counting the number of distinct asteroids in the entire sector.Consider the 10 x 10 space shown below on the left. The '*'s represent asteroid chunks, and each '.' represents a .vast void of empty space. The diagram on the right shows an arbitrary numbering applied to the asteroids.

<span style="font-size:14px;"></span>

It's easy to see there are 7 asteroids in this sector.

輸入

* Line 1: A single integer: N* Lines 2..N+1: Line i+1 contains row i of the asteroid field: N characters

輸出

* Line 1: A single integer indicating the number of asteroids in the field.

樣例輸入

樣例輸出

題目意思:數牛群唄...和上面那題一樣的都是上下左右四個方向,但是這個地圖范圍是1000*1000,所以要用廣搜。

用廣搜一般都是隊列+結構體哦~

#include<cstdio>#include<cstring>#include<queue>using namespace std;int s,t;char m[1001][1001];	struct node{int x,y;};node pre,cur;int dir[4][2]={1,0,0,1,-1,0,0,-1};void bfs(int a,int b){    int i,x,y;    queue<node>que;    m[a][b]='.';    cur.x=a,cur.y=b;    que.push(cur);    while(!que.empty())    {        cur=que.front(),que.pop();        for(i=0;i<4;i++)        {            x=cur.x+dir[i][0];            y=cur.y+dir[i][1];            if(x>=0&&x<t&&y>=0&&y<t&&m[x][y]=='*')            {                m[x][y]='.';                pre.x=x,pre.y=y;                que.push(pre);            }        }            }}int main(){    int i,j,k;	s=0;	scanf("%d",&t);	for(i=0;i<t;i++)	scanf("%s",m[i]);	for(i=0;i<t;i++)	{		for(j=0;j<t;j++)		{			if(m[i][j]=='*')			{bfs(i,j);s++;}		}	} 	printf("%d/n",s);	}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
www.亚洲男人天堂| 久久99视频免费| 精品久久久久久国产91| 精品在线欧美视频| 亚洲毛片在线免费观看| 亚洲品质视频自拍网| 日韩av不卡电影| 伊人久久五月天| 国产精品啪视频| 欧美性在线观看| 青青久久aⅴ北条麻妃| 久久精品中文字幕一区| 国产精品成人一区二区| 69国产精品成人在线播放| 久久69精品久久久久久国产越南| 亚洲精品小视频在线观看| 国产精品男人的天堂| 热久久99这里有精品| 91sa在线看| 97在线精品国自产拍中文| 欧美性猛交xxxxx免费看| 一个人www欧美| 久久精品一偷一偷国产| 中文字幕亚洲一区二区三区| 日本久久久a级免费| 精品国模在线视频| 国产精品欧美一区二区三区奶水| 欧美激情亚洲另类| 一本色道久久88综合日韩精品| 日韩亚洲综合在线| 成人午夜激情免费视频| 亚洲在线免费视频| 成人黄色激情网| 国产成人精品在线视频| 91九色综合久久| 一级做a爰片久久毛片美女图片| 欧美亚洲国产成人精品| 日韩欧美国产高清91| 亚洲成人三级在线| 国产精品视频精品视频| 欧美激情videoshd| 欧美另类精品xxxx孕妇| 久久97久久97精品免视看| 亚洲片在线资源| 精品成人乱色一区二区| 久久久噜久噜久久综合| 亚洲人成网7777777国产| 精品视频中文字幕| 亚洲高清免费观看高清完整版| 色多多国产成人永久免费网站| 91高清在线免费观看| 国产suv精品一区二区| 最近2019免费中文字幕视频三| 欧美日韩成人在线视频| 成人h视频在线观看播放| 狠狠躁夜夜躁久久躁别揉| 美女啪啪无遮挡免费久久网站| www.亚洲免费视频| 少妇激情综合网| 亚洲激情自拍图| 国产免费一区二区三区香蕉精| 欧日韩不卡在线视频| 国产成人综合亚洲| 国产不卡一区二区在线播放| 国产999精品久久久影片官网| 91中文字幕一区| 最近中文字幕2019免费| 91牛牛免费视频| 中文字幕亚洲欧美日韩在线不卡| 18久久久久久| 2019日本中文字幕| 中文字幕亚洲图片| 国产欧美精品va在线观看| 日韩av免费看| 亚洲国产精品推荐| 亚洲性日韩精品一区二区| 国产精品午夜一区二区欲梦| 久久久久久久久久久91| 国精产品一区一区三区有限在线| 欧美丰满少妇xxxxx做受| 亚洲精品美女久久| 日韩成人在线观看| 亚洲欧美一区二区精品久久久| 2020欧美日韩在线视频| 国产亚洲精品va在线观看| 日韩美女免费视频| 在线日韩日本国产亚洲| 久久91精品国产91久久跳| 成人国产精品一区| 亚洲欧美日韩天堂一区二区| 欧美一级大片视频| 成人在线视频网| 自拍偷拍免费精品| 亚洲精品国产综合区久久久久久久| 97成人精品视频在线观看| 日韩国产精品视频| 精品久久久久久久久久久久久久| 91国内免费在线视频| 国产精品美女久久久久av超清| 久久久噜噜噜久久中文字免| 日韩欧美中文免费| 九色精品美女在线| 久久97久久97精品免视看| 91久久久久久久一区二区| 亚洲人成人99网站| 日本欧美爱爱爱| 国内精品久久久久影院优| 久久久久久久久久久人体| 国产99久久精品一区二区永久免费| 亚洲韩国欧洲国产日产av| 亚洲性夜色噜噜噜7777| 久久躁日日躁aaaaxxxx| 国产丝袜一区二区| 欧美理论在线观看| 亚洲人在线观看| 亚洲va久久久噜噜噜久久天堂| 国产免费一区视频观看免费| 国产成人免费av电影| 国产精品99久久久久久www| 欧美日韩亚洲网| 国产不卡视频在线| 亚洲精品国产综合区久久久久久久| 亚洲肉体裸体xxxx137| 国产在线日韩在线| 欧美一乱一性一交一视频| 久久久这里只有精品视频| 国产日韩欧美一二三区| 国产成人鲁鲁免费视频a| 国产亚洲一区二区精品| 少妇高潮 亚洲精品| 国产欧美一区二区三区在线看| 91免费观看网站| 国产精品久久久久国产a级| 欧美国产第二页| 亚洲福利精品在线| 国产成人aa精品一区在线播放| 国产999精品久久久影片官网| 91av成人在线| 不卡伊人av在线播放| 中文字幕日韩av综合精品| 久久夜精品va视频免费观看| 国产色综合天天综合网| 日韩欧美福利视频| 日韩成人免费视频| 亚洲裸体xxxx| 亚洲精品久久视频| 欧美黑人xxxⅹ高潮交| 国产成人综合一区二区三区| 久久久最新网址| 国产精品狠色婷| 久久久久久亚洲精品不卡| 色综合视频一区中文字幕| 久久人人爽人人| 91在线观看免费网站| 欧美极品在线视频| 亚洲风情亚aⅴ在线发布| 97视频免费观看| 国产一区二区三区欧美| 国产a级全部精品| 欧美成人免费全部| 91在线视频免费| 51精品国产黑色丝袜高跟鞋| 欧美xxxwww| 成人国产在线激情|