Created
December 10, 2012 07:17
-
-
Save hamadu/4249001 to your computer and use it in GitHub Desktop.
InputChecker of problemI in WUPC2nd.
This file contains 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.File; | |
import java.io.FileReader; | |
import java.io.InputStreamReader; | |
public class InputCheckerI { | |
public static void main(String[] args) throws Exception { | |
String[] substasks = new String[]{"small", "large1", "large3"}; | |
for (String substask : substasks) { | |
File inputDir = new File("/path/to/the/input/directory/" + substask); | |
for (File file : inputDir.listFiles()) { | |
BufferedReader reader = new BufferedReader(new FileReader(file)); | |
int limitHive = 10000; | |
int limitSize = 500; | |
int maxtype = 3; | |
if ("small".equals(substask)) { | |
limitHive = 100; | |
limitSize = 100; | |
maxtype = 1; | |
} else if ("large1".equals(substask)) { | |
maxtype = 1; | |
} | |
if (!check(reader, limitHive, limitSize, maxtype)) { | |
System.err.println("err:" + file.getName()); | |
} else { | |
System.err.println("ok"); | |
} | |
reader.close(); | |
} | |
} | |
} | |
private static boolean check(BufferedReader reader, int limitHive, int limitSize, int maxtype) { | |
try { | |
int N = Integer.valueOf(reader.readLine()); | |
if (1 <= N && N <= limitHive) { | |
} else { | |
System.err.println("invalid N"); | |
return false; | |
} | |
for (int i = 0 ; i < N ; i++) { | |
String[] hive = reader.readLine().split(" "); | |
if (hive.length != 4) { | |
return false; | |
} | |
int type = Integer.valueOf(hive[0]); | |
int x = Integer.valueOf(hive[1]); | |
int y = Integer.valueOf(hive[2]); | |
int size = Integer.valueOf(hive[3]); | |
if (Math.abs(x) > limitSize) { | |
return false; | |
} | |
if (Math.abs(y) > limitSize) { | |
return false; | |
} | |
if (1 <= size && size <= limitSize) { | |
} else { | |
return false; | |
} | |
if (1 <= type && type <= maxtype) { | |
} else { | |
return false; | |
} | |
} | |
return true; | |
} catch (Exception e) { | |
return false; | |
} | |
} | |
static boolean[] visited; | |
public static void dfs(int i, int N, boolean[][] g) { | |
if (visited[i]) { | |
return; | |
} | |
visited[i] = true; | |
for (int j = 1 ; j <= N ; j++) { | |
if (g[i][j]) { | |
dfs(j, N, g); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment