"Codevs" 1293

Source: Internet
Author: User

Input/Output sample

Idea: See the topic I Meng first thought of certainly is to beg unicom fast, but this unicom fast a bit peculiar, because

So he is a unicom fast. There are three ways to solve the problem: 1) wide search (this conforms to the Basic Law), 2) and check set; 3) Irrigation method

But Konjac Konjac wrote and looked at the set.

The code is as follows:

1 varN,m,i,j,ans:longint;2C:Array[0.. +,0.. +] ofChar;3PreArray[0..10000000] ofLongint;4A:Array[0..10000000] ofBoolean;5 functionFind (X:longint): Longint;6 begin7  ifPre[x]=x Thenexit (x);8find:=find (Pre[x]);9pre[x]:=find;Ten End; One procedurejoin (x,y:longint); A varFx,fy:longint; - begin -Fx:=find (x); fy:=find (y); the  ifFx<>fy Thenpre[fx]:=find (FY); - End; - begin - readln (n,m); +   fori:=1  toN*m Dopre[i]:=i; -   fori:=1  toN Do +   begin A     forj:=1  toM Do at     begin - read (c[i,j]); -          ifc[i,j]='#'  Thena[(I-1) *m+j]:=true; -          ifc[i,j]='-'  Thena[(I-1) *m+j]:=false; -     End; - Readln; in   End; -    fori:=1  toN Do to    begin +      forj:=1  toM Do -      begin the       ifc[i,j]='#'  Then *       begin $            ifc[i+1, j]='#'  ThenJoin (I*m+j, (i-1) *m+j);Panax Notoginseng            ifc[i,j+1]='#'  ThenJoin ((I-1) *m+j+1, (I-1) *m+j); -             ifc[i+2, j]='#'  ThenJoin ((i+1) *m+j, (I-1) *m+j); the             ifc[i,j+2]='#'  ThenJoin ((I-1) *m+j+2, (I-1) *m+j); +             ifc[i+1, J-1]='#'  ThenJoin (i*m+j-1, (I-1) *m+j); A             ifc[i+1, j+1]='#'  ThenJoin (i*m+j+1, (I-1) *m+j);//In fact, not 12 points all to be sentenced again, because there are repeated coverage of the part the       End; +      End; -    End; $    fori:=1  toN*m Do ifPre[i]=i Then ifA[i] ThenInc (ANS);//statistics "Unicom fast" number $ writeln (ans); - End.
View Code

This is Konjac Konjac first ac of mention, send an essay commemorative (^_^)

"Codevs" 1293

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.