GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Java/revegetate.java at master · javaarchive/Java
This repository was archived by the owner on Feb 29, 2024. It is now read-only.
Expand file tree/ Copy pathrevegetate.javaMore file actions 96 lines (85 loc) · 2.77 KB / Copy pathrevegetate.javaFile metadata and controls96 lines (85 loc) · 2.77 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 import java.io.*; import java.util.*; public class revegetate { public static final int OFFSET = -1; public static final char NULL = '\u0000'; public static void main(String[] args) throws IOException, InvalidInputException{ // TODO Auto-generated method stub char[][] graph; int N,M; BufferedReader f = new BufferedReader(new FileReader("11.in")); StringTokenizer st = new StringTokenizer(f.readLine()); N = Integer.parseInt(st.nextToken()); M = Integer.parseInt(st.nextToken()); graph = new char[N][N]; // Adjancey Matrix for(int i = 0; i < M; i ++) { st = new StringTokenizer(f.readLine()); char state = st.nextToken().charAt(0); int x = Integer.parseInt(st.nextToken()) + OFFSET; int y = Integer.parseInt(st.nextToken()) + OFFSET; // Validate Input //if(!(graph[x][y] == NULL || graph[x][y] == state)) { //throw new InvalidInputException("Improper input, conflicting nodes!"); //} // End input validation graph[x][y] = state; graph[y][x] = state; } f.close(); // begin algorthim int[] prevValues = new int[N]; for(int i = 0; i < N; i ++) { if(prevValues[i] == 0) { prevValues = sim(0,graph,prevValues); AnswerBuilder.append('0'); } } System.out.println(Arrays.toString(prevValues)); for(int i = 0; i < N; i ++) { for(int j = 0; j < N; j ++) { System.out.print((int) graph[i][j] + (j<N-1 ? ", ":"")); } System.out.println(); } PrintWriter pw = new PrintWriter(new FileWriter("revegetate.out")); pw.println(AnswerBuilder.toString()); pw.close(); } public static StringBuilder AnswerBuilder = new StringBuilder("1"); //public static boolean atLeastOneConnected = false; public static int[] sim(int curNode,char[][] graph,int[] prevValues) { // int[][] grid int N = graph.length; //int[][] grid = new int[N][N]; int[] prevNodes = new int[N]; //int[] prevValues= new int[N]; prevValues[curNode] = 0; Queue<Integer> pastures = new LinkedList<Integer>(); pastures.add(curNode); //Queue<Character> states = new LinkedList<Character>(); //atLeastOneConnected = false; while(!(pastures.isEmpty())) { int currentSim = pastures.poll(); for(int i = 0; i < graph.length; i ++) { if(i == currentSim) { continue; } //char temp; if(prevValues[i] == 0 && graph[currentSim][i] != 0) { //atLeastOneConnected = true; prevValues[i] = currentSim; // Mark as visited pastures.add(i); } } } return prevValues; } } class InvalidInputException extends Exception { /** * */ private static final long serialVersionUID = -1472101612368218565L; public InvalidInputException(String errorMessage) { super(errorMessage); } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |