Nyoj 1237 largest island (Dfs)

Source: Internet
Author: User

Describe

Mysterious Sea, thrilling adventure Road, salvage the seabed treasures, fierce naval warfare, pirates Rob Rich and so on. Pirates of the Caribbean, you know? Captain Jack is driving his own warship, Black Pearl 1th, to conquer the Pirates of each island and finally become the Pirate King.  

Input
Line 1th: M N T, which indicates the length of the sea area, the width and the size of one unit represents the next number of m rows, each line has N 01 series and interspersed with some spaces. 0 means sea water, 1 means land, where the space is useless, can be ignored.

Output
Output line with 2 integers, a space interval representing the number of islands across the sea, and the area of the largest island

Sample input
8  -  About 00000000 00000000 0000110011000000 0001111000111000 0000000  xx 0000000 00111  111000001  Ten 001110000  0000000 0100001111 111100 0000000000000000

Sample output
5 990

Tips
1<m, n≤1<t≤100000

Source
eighth session of Henan Province Program design Competition

Direct DFS violence can be.

1 #pragmaComment (linker, "/stack:1024000000,1024000000")2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cmath>6#include <math.h>7#include <algorithm>8#include <queue>9#include <Set>Ten#include <bitset> One#include <map> A#include <vector> -#include <stdlib.h> - using namespacestd; the #definell Long Long - #defineEPS 1e-10 - #defineMOD 1000000007 - #defineN 100000 + #defineNN 506 - #defineINF 1e12 + intn,m,c; A CharS[n]; at CharMp[nn][nn]; - intVis[nn][nn]; - intans; - intdirx[]={0,0,-1,1,-1,-1,1,1}; - intdiry[]={-1,1,0,0,-1,1,-1,1}; - intOne ; in voidDfsintXinty) { -  toone++; +ans=Max (One,ans); -vis[x][y]=1; the      for(intI=0;i<8; i++){ *         intDX = x+Dirx[i]; $         intDY = y+Diry[i];Panax Notoginseng         if(dx<0|| Dx>=n | | Dy <0|| DY&GT;=M)Continue; -         if(Vis[dx][dy])Continue; the         if(mp[dx][dy]=='0')Continue; + DFS (dx,dy); A     } the } + intMain () - { $      while(SCANF ("%d%d%d", &n,&m,&c) = =3){ $ GetChar (); -          for(intI=0; i<n;i++){ - gets (s); the             intlen=strlen (s); -             intk=0;Wuyi              for(intj=0; j<len;j++){ the                 if(s[j]==' ')Continue; -mp[i][k++]=S[j]; Wu             } -         } About       /* $ printf ("----------------------\ n"); - for (int i=0;i<n;i++) { - for (int j=0;j<m;j++) { - printf ("%c", Mp[i][j]); A             } + printf ("\ n"); the         } - printf ("----------------------\ n"); $       */ theans=-1; the         intw=0; thememset (Vis,0,sizeof(Vis)); the          for(intI=0; i<n;i++){ -              for(intj=0; j<m;j++){ in                 if(Vis[i][j])Continue; the                 if(mp[i][j]=='0')Continue; thew++; AboutOne=0; the DFS (I,J); the             }     the          }     +          //printf ("&&&%d\n", ans); -printf"%d%d\n", w,ans*c); the     }Bayi     return 0; the}
View Code

Nyoj 1237 largest island (Dfs)

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.