Skip to content

Commit

Permalink
Add GCJ 2016 Round 1C
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffrey-xiao committed Apr 29, 2019
1 parent 6183109 commit 16e73a8
Show file tree
Hide file tree
Showing 3 changed files with 237 additions and 0 deletions.
89 changes: 89 additions & 0 deletions src/contest/codejam/GCJ_2016_Round_1C_A.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import java.io.*;
import java.util.*;

public class GCJ_2016_Round_1C_A {

static BufferedReader br;
static PrintWriter out;
static StringTokenizer st;

static int T, N;

public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(new OutputStreamWriter(System.out));
// br = new BufferedReader(new FileReader("in.txt"));
// out = new PrintWriter(new FileWriter("out.txt"));

T = readInt();
for (int t = 1; t <= T; t++) {
N = readInt();
PriorityQueue<State> pq = new PriorityQueue<State>();
for (int i = 0; i < N; i++) {
pq.offer(new State((char)(i + 'A'), readInt()));
}

out.printf("Case #%d: ", t);
while (pq.size() > 2) {
State s = pq.poll();
out.print(s.party + " ");
if (s.count > 1) {
pq.offer(new State(s.party, s.count - 1));
}
}
int count = pq.peek().count;
char a = pq.poll().party;
char b = pq.poll().party;
for (int i = 0; i < count; i++) {
out.print(a + "" + b);
if (i != count - 1) {
out.print(" ");
}
}
out.println();
}

out.close();
}

static class State implements Comparable<State> {
char party;
int count;

State(char party, int count) {
this.party = party;
this.count = count;
}

@Override
public int compareTo(State s) {
return s.count - count;
}
}

static String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine().trim());
return st.nextToken();
}

static long readLong() throws IOException {
return Long.parseLong(next());
}

static int readInt() throws IOException {
return Integer.parseInt(next());
}

static double readDouble() throws IOException {
return Double.parseDouble(next());
}

static char readCharacter() throws IOException {
return next().charAt(0);
}

static String readLine() throws IOException {
return br.readLine().trim();
}
}
73 changes: 73 additions & 0 deletions src/contest/codejam/GCJ_2016_Round_1C_B.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import java.io.*;
import java.util.*;

public class GCJ_2016_Round_1C_B {

static BufferedReader br;
static PrintWriter out;
static StringTokenizer st;

static int T, B;
static long M;

public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(new OutputStreamWriter(System.out));
br = new BufferedReader(new FileReader("/home/jeffreyxiao/Downloads/B-large-practice.in"));
out = new PrintWriter(new FileWriter("/home/jeffreyxiao/Downloads/out.txt"));

T = readInt();
for (int t = 1; t <= T; t++) {
B = readInt();
M = readLong();
boolean[][] adj = new boolean[B][B];
for (int i = 1; i < B; i++) {
adj[0][i] = true;
}
if (M > 1L << (B - 2)) {
out.printf("Case #%d: IMPOSSIBLE%n", t);
} else {
out.printf("Case #%d: POSSIBLE%n", t);
String first = Long.toString(M - 1, 2) + "1";
while (first.length() < B) {
first = "0" + first;
}
out.println(first);
for (int i = 1; i < B; i++) {
for (int j = 0; j < B; j++) {
out.print(i < j ? '1' : '0');
}
out.println();
}
}
}

out.close();
}

static String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine().trim());
return st.nextToken();
}

static long readLong() throws IOException {
return Long.parseLong(next());
}

static int readInt() throws IOException {
return Integer.parseInt(next());
}

static double readDouble() throws IOException {
return Double.parseDouble(next());
}

static char readCharacter() throws IOException {
return next().charAt(0);
}

static String readLine() throws IOException {
return br.readLine().trim();
}
}
75 changes: 75 additions & 0 deletions src/contest/codejam/GCJ_2016_Round_1C_C.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import java.io.*;
import java.util.*;

public class GCJ_2016_Round_1C_C {

static BufferedReader br;
static PrintWriter out;
static StringTokenizer st;

static int T, J, P, S, K;

public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(new OutputStreamWriter(System.out));
// br = new BufferedReader(new FileReader("in.txt"));
// out = new PrintWriter(new FileWriter("out.txt"));

T = readInt();
for (int t = 1; t <= T; t++) {
J = readInt();
P = readInt();
S = readInt();
K = readInt();

if (K >= S) {
out.printf("Case #%d: %d%n", t, J * P * S);
for (int j = 1; j <= J; j++) {
for (int p = 1; p <= P; p++) {
for (int s = 1; s <= S; s++) {
out.printf("%d %d %d%n", j, p, s);
}
}
}
} else {
out.printf("Case #%d: %d%n", t, J * P * K);
for (int j = 1; j <= J; j++) {
for (int p = 1; p <= P; p++) {
for (int k = 0; k < K; k++) {
int s = (j + p + k) % S + 1;
out.printf("%d %d %d%n", j, p, s);
}
}
}
}
}

out.close();
}

static String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine().trim());
return st.nextToken();
}

static long readLong() throws IOException {
return Long.parseLong(next());
}

static int readInt() throws IOException {
return Integer.parseInt(next());
}

static double readDouble() throws IOException {
return Double.parseDouble(next());
}

static char readCharacter() throws IOException {
return next().charAt(0);
}

static String readLine() throws IOException {
return br.readLine().trim();
}
}

0 comments on commit 16e73a8

Please sign in to comment.