forked from jeffrey-xiao/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6183109
commit 16e73a8
Showing
3 changed files
with
237 additions
and
0 deletions.
There are no files selected for viewing
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
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(); | ||
} | ||
} |
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
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(); | ||
} | ||
} |
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
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(); | ||
} | ||
} |