Java and ACM -- search for Java (HDU 1241)

Source: Internet
Author: User

At the beginning, I wrote something in Java. Thank you for your advice.

 

1. the handler is located in Java. util. *.

2. Java's string class is not like the string in C ++. Data input and hash are affected.

 

In general, it is quite adaptive.

 

 

Import Java. util. *; <br/> public class main {<br/>/** <br/> * @ Param ARGs <br/> */<br/> static int N, m; <br/> static final int maxn = 101; <br/> static char map [] [] = new char [maxn] [maxn]; <br/> static int dir [] [] = {0, 1}, {0,-1}, {-1, 0}, {1, 0 }, {1, 1}, {-1,-1}, {-1, 1}, {1,-1 }}; </P> <p> static Boolean inmap (int r, int C) {<br/> return r> = 0 & C> = 0 & R <n & C <m; <br/>}</P> <p> static void DFS (int r, int c) {<br/> map [r] [c] = '*'; <br/> int _ r, _ C, I; <br/> for (I = 0; I <8; I ++) {<br/> _ r = R + dir [I] [0]; <br/> _ C = C + dir [I] [1]; <br/> If (inmap (_ r, _ C) & map [_ r] [_ c] = '@') {<br/> DFS (_ r, _ C ); <br/>}</P> <p> Public static void main (string [] ARGs) {<br/> // todo auto-generated method stub <br/> int I, j, CNT; <br/> string a = new string (); <br/> memory in = new memory (system. in); <br/> while (true) {<br/> N = in. nextint (); <br/> M = in. nextint (); <br/> If (n = 0 & M = 0) break; <br/> for (I = 0; I <N; I ++) {<br/> A = in. next (); <br/> map [I] =. tochararray (); <br/>}< br/> for (CNT = I = 0; I <n; I ++) {<br/> for (j = 0; j <m; j ++) {<br/> If (Map [I] [J] = '@') {<br/> CNT ++; <br/> DFS (I, j); <br/>}< br/> system. out. println (CNT); <br/>}</P> <p >}< br/>

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.