Last active
          December 15, 2015 03:09 
        
      - 
      
 - 
        
Save lgo/5192253 to your computer and use it in GitHub Desktop.  
    DWITE 4 Round 3 Solutions
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import java.io.BufferedReader; | |
| import java.io.BufferedWriter; | |
| import java.io.FileReader; | |
| import java.io.FileWriter; | |
| public class S1 | |
| { | |
| public static void main(String[] args) throws Exception { | |
| BufferedReader br = new BufferedReader(new FileReader("IN1.txt")); | |
| BufferedWriter bw = new BufferedWriter(new FileWriter("OUT1.txt")); | |
| final String c = ":"; | |
| for (int i = 0; i < 5; i++) { | |
| String temp[] = br.readLine().split(" "); | |
| String clock[] = temp[0].split(":"); | |
| int h = Integer.parseInt(clock[0]); | |
| int f = Integer.parseInt(temp[1]); | |
| int t = Integer.parseInt(temp[2]); | |
| h += f + t; | |
| h %= 24; | |
| bw.write(h + c + clock[1] + c + clock[2]); | |
| bw.newLine(); | |
| bw.flush(); | |
| } | |
| br.close(); | |
| bw.close(); | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import java.io.BufferedReader; | |
| import java.io.BufferedWriter; | |
| import java.io.FileReader; | |
| import java.io.FileWriter; | |
| public class S2 | |
| { | |
| public static void main(String[] args) throws Exception { | |
| BufferedReader br = new BufferedReader(new FileReader("IN2.txt")); | |
| BufferedWriter bw = new BufferedWriter(new FileWriter("OUT2.txt")); | |
| for (int i = 0; i < 5; i++) { | |
| String s = br.readLine(); | |
| int amount = 0; | |
| out: | |
| for (int r = 1; r < s.length(); r++) { | |
| for (int j = 0; j < s.length(); j++) { | |
| if (s.charAt(j) == s.charAt(r + j)) { | |
| if (j + r == s.length() - 1) { | |
| amount = j + 1; | |
| break out; | |
| } | |
| continue; | |
| } else { | |
| break; | |
| } | |
| } | |
| } | |
| bw.write(s + s.substring(amount) + " " + amount); | |
| bw.newLine(); | |
| bw.flush(); | |
| } | |
| br.close(); | |
| bw.close(); | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import java.io.BufferedReader; | |
| import java.io.BufferedWriter; | |
| import java.io.FileReader; | |
| import java.io.FileWriter; | |
| public class S3 | |
| { | |
| static boolean[][] grid = null; | |
| public static void main(String[] args) throws Exception | |
| { | |
| BufferedReader br = new BufferedReader(new FileReader("IN3.txt")); | |
| BufferedWriter bw = new BufferedWriter(new FileWriter("OUT3.txt")); | |
| for (int i = 0; i < 1; i++) | |
| { | |
| int size = Integer.parseInt(br.readLine()); | |
| grid = new boolean[size][size]; | |
| for (int j = 0; j < size; j++) | |
| { | |
| char[] temp = br.readLine().toCharArray(); | |
| for (int p = 0; p < size; p++) | |
| { | |
| grid[p][j] = temp[p] == '#' ? true : false; | |
| } | |
| } | |
| int count = search(); | |
| for (int j = 0; j < size; j++) { | |
| for (int p = 0; p < size; p++) { | |
| if (grid[j][p]) count++; | |
| } | |
| } | |
| bw.write(Integer.toString(count)); | |
| bw.newLine(); | |
| bw.flush(); | |
| } | |
| br.close(); | |
| bw.close(); | |
| } | |
| private static int search() | |
| { | |
| return search(0, grid.length - 1, 0, 0, 0, false); | |
| } | |
| private static int search(int x, int y, int base, int cur_base, int layer, boolean tri) | |
| { | |
| int count = 0; | |
| if (grid[x][y]) | |
| { | |
| if (!tri) | |
| base++; | |
| cur_base = base - (2 * layer); | |
| if (layer != 0 && layer == (base - 1) / 2) | |
| return 1; | |
| if (base > 1 && cur_base % 2 == 1 ) | |
| if (y - 1 >= 0) | |
| //FIXME navigation of x axis, only issue | |
| count += search(x - (int) Math.floor(0.5 * cur_base), y - 1, base, base, layer + 1, true); | |
| } | |
| else | |
| base = 0; | |
| if (x + 1 < grid.length) | |
| count += search(x + 1, y, base, 0, 0, false); | |
| else if (y > 1) | |
| count += search(0, y - 1, base, 0, 0, false); | |
| return count; | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Rescursively call each spot, and going in each direction | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment