Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
附代码,哪位大牛能帮忙解答下?In Reply To:把JAVA代码改成C++的,就可以AC,JAVA就RE,难道JAVA的栈有问题? Posted by:wolfshow at 2006-12-25 09:40:21 import java.util.*; import java.io.*; public class Main { public static char[][] pool = new char[128][128]; public static boolean[][] f = new boolean[128][128]; public static int[] dr = {-1,-1,-1,0,1,1,1,0}; public static int[] dc = {-1,0,1,1,1,0,-1,-1}; public static int r,c; public static void main(String args[]) throws IOException { //FileReader fin = new FileReader("1.txt"); Scanner cin = new Scanner(System.in); //while(cin.hasNext()) { r = cin.nextInt(); c = cin.nextInt(); // if(r == 0 && c == 0) break; for(int i = 0; i < r; i++) { String s = cin.next(); pool[i] = s.toCharArray(); //System.out.println(pool[i]); } int count = 0; for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) f[i][j] = false; for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) { if(pool[i][j] == 'W' && !f[i][j]) { DFS(i,j); count++; } } System.out.println(count); } } public static void DFS(int rr,int cc) { f[rr][cc] = true; for(int i = 0; i < 8; i++) { int tr = rr + dr[i]; int tc = cc + dc[i]; if(tr >= 0 && tr < r && tc >= 0 && tc < c) { if(pool[tr][tc] == 'W' && !f[tr][tc]) { DFS(tr,tc); } } } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator