Ecnuoj 2856 to the sky

Source: Internet
Author: User

Looking at the starry sky

Time limit:1000ms Memory limit:65536kb
Total submit:373 accepted:145

Description

I look up at the starry sky

It is so vast and deep;

The Infinite Truth,

Let me search and follow with bitterness.

I look up at the starry sky

It is so solemn and holy;

That awe-inspiring justice,

Let me be full of love, I feel awe.

I look up at the starry sky

It is so free and quiet;

The bosom of the broad,

Let my soul perch and snuggle.

I look up at the starry sky

It is so magnificent and glorious;

The Eternal hot,

Let my heart ignite the flame of Hope, the spring Thunder.

The stars have countless constellations, and today you can count the number of constellations in the sky.

Assuming the sky is a w*h plane, constellations are made up of neighboring stars. The conditions adjacent to the two stars are horizontal or vertical or diagonal. As the sky for 10*5:

.. *.....**

.**.. *****

.*...*....

.. ****.***

.. ****.***

The stars are ' * ', the blank part is '. ', there are 2 constellations in the sky.

Input

Line 1th: Two integers separated by a space, 1<=w<=80 and 1<=h<=1000.

2nd to h+1: Each row contains a W ' * ' or '. ', which represents the composition of the starry sky.

Output

Line: Indicates the number of stars in the current constellation.

Sample Input

10 5
.. *.....**
.**.. *****
.*...*....
.. ****.***
.. ****.***

15 8
**.**......*.. *
.. *.**.*...*...
*.*.**.*****.**
...***.****.**.
...**.. *.*.....
*****.. *****.. *
....**...*.. *..
*.*...*.*.*.***

Sample Output

2
7

Source

Problem solving: Searching

1#include <bits/stdc++.h>2 #definePII pair<int,int>3 using namespacestd;4 intw,h;5 Chartable[1010][ -];6 Const intdir[8][2] = {7-1,0,1,0,0,-1,0,1,8-1,-1,1,1,-1,1,1,-19 };Ten BOOLIsIn (intXinty) { One     returnX >=0&& x < h && y >=0&& y <W; A } -queue< PII >Q; - voidBFsintXinty) { the      while(!q.empty ()) Q.pop (); - Q.push (PII (x, y)); -Table[x][y] ='.'; -      while(!Q.empty ()) { +PII now =Q.front (); - Q.pop (); +          for(inti =0; I <8; ++i) { Ax = Now.first + dir[i][0]; aty = Now.second + dir[i][1]; -             if(IsIn (x, y) && table[x][y] = ='*') { - Q.push (PII (x, y)); -Table[x][y] ='.'; -             } -         } in     } - } to intMain () { +      while(~SCANF ("%d%d",&w,&h)) { -          for(inti =0; I < H; ++i) thescanf"%s", Table[i]); *         intRET =0; $          for(inti =0; I < H; ++i) {Panax Notoginseng              for(intj =0; J < W; ++j) { -                 if(Table[i][j] = ='*') { theret++; + BFS (i,j); A                 } the             } +         } -printf"%d\n", ret); $     } $     return 0; -}
View Code

Ecnuoj 2856 to the sky

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.