Created
January 24, 2017 17:42
-
-
Save austinschwartz/abe38314d4fbeec380ab1a14c2ac0ce7 to your computer and use it in GitHub Desktop.
Boxes AC O(n^6) code
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.*; | |
import java.util.*; | |
public class Main { | |
public static PrintWriter out; | |
public static void main(String[] args) { | |
MyScanner sc = new MyScanner(); | |
out = new PrintWriter(new BufferedOutputStream(System.out)); | |
int[] boxes = new int[6]; | |
for (int i = 0; i < 6; i++) | |
boxes[i] = sc.nextInt(); | |
int t1 = sc.nextInt(); | |
int t2 = sc.nextInt(); | |
Arrays.sort(boxes); | |
for (int i = 0; i < 6; i++) { | |
for (int j = 0; j < 6; j++) { | |
if (boxes[j] > boxes[i] || i == j) continue; | |
for (int k = 0; k < 6; k++) { | |
if (boxes[k] > boxes[j] || k == j) continue; | |
for (int l = 0; l < 6; l++) { | |
for (int m = 0; m < 6; m++) { | |
if (boxes[m] > boxes[l] || m == l) continue; | |
for (int n = 0; n < 6; n++) { | |
if (boxes[n] > boxes[m] || m == n) continue; | |
if (boxes[i] + boxes[j] + boxes[k] == t1 && | |
boxes[l] + boxes[m] + boxes[n] == t2) | |
System.out.println(boxes[i] + " " + boxes[j] + " " + boxes[k] + " " + boxes[l] + " " + boxes[m] + " " + boxes[n]); | |
} | |
} | |
} | |
} | |
} | |
} | |
out.close(); | |
} | |
public static class MyScanner { | |
BufferedReader br; | |
StringTokenizer st; | |
public MyScanner() { | |
br = new BufferedReader(new InputStreamReader(System.in)); | |
} | |
public boolean hasNext() { | |
try { | |
boolean a = br.ready(); | |
return a; | |
} catch (IOException e) { | |
return false; | |
} | |
} | |
public String next() { | |
while (st == null || !st.hasMoreElements()) { | |
try { | |
st = new StringTokenizer(br.readLine()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
return st.nextToken(); | |
} | |
public int nextInt() { | |
return Integer.parseInt(next()); | |
} | |
public long nextLong() { | |
return Long.parseLong(next()); | |
} | |
public double nextDouble() { | |
return Double.parseDouble(next()); | |
} | |
public char nextChar() { | |
return next().charAt(0); | |
} | |
public String nextLine() { | |
String str = ""; | |
try { | |
str = br.readLine(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return str; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment