id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
dd1e1739-f967-4fba-b443-229c4dbf9283 | public void setCount(int count) {
this.count = count;
} |
6b029513-6f69-469a-8e88-5ce10eb2df4b | public static void main(String[] args) {
int bitmask = 0x00FF;
int val = 0x2222;
// prints "2"
System.out.println(val & bitmask);
int g = 20 >> 2;
System.out.println("20>>2 = " + g);
System.out.println(Integer.toBinaryString(8));
System.out.println(Integer.toBinaryString(~8));
System.out.println(Integer.toBinaryString(-8>>1));
System.out.println(Integer.toBinaryString(00+1));
System.out.println(Integer.toBinaryString(3<<1));
System.out.println(Integer.toBinaryString(5^2));
} |
983a3a1b-7016-4cd2-97c7-50ae1f2e3d4b | public long theCount(int[] answers) {
final int length = answers.length;
Arrays.sort(answers);
int i = 0;
int count = 0;
while (i + 1 < length && answers[i] == count && answers[i + 1] == count) {
count++;
i += 2;
}
final int countFirst = count;
while (i < length && answers[i] == count) {
i++;
count++;
}
if (i != length)
return 0;
long result = 1 << countFirst;
if (countFirst != count)
result <<= 1;
return result;
} |
c6dd0a59-bca4-4dd9-b7c0-4dd889589ca7 | public static void main(String[] args) {
Zoo zoo = new Zoo();
int a[] = { 0, 1, 2, 3, 4 };
System.out.println(zoo.theCount(a));
} |
bc4b3c66-0010-4321-bd00-82860fb6a2b1 | public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
double number;
System.out.println("Enter number >");
number = s.nextDouble();
double sqr = Math.sqrt(number);
// System.out.println(sqr);
double num = sqr;
double x;
x = num % 1;
x = num - Math.floor(num);
if (x > 0) {
System.out.println("False");
} else {
System.out.println(sqr);
}
} |
cf9fd96b-7786-44eb-a2cb-0b59400891b6 | public int bestMove(String[] redPieces, String[] blackPeices, String whoseTurn) {
grid = createGrid(redPieces, blackPeices);
printGrig(grid);
mainGrid = grid.clone();
// System.arraycopy(grid, 0, mainGrid, 0, grid.length);
if (whoseTurn.equals("Red")) {
whoseTurn = "R";
} else {
whoseTurn = "B";
}
int count = solve(redPieces, blackPeices, whoseTurn);
// printGrig(grid);
// printGrig(mainGrid);
return count;
} |
c0a9acb2-73ba-4199-9470-6e9d4fb4bd3a | private int solve(String[] redPieces, String[] blackPeices, String whoseTurn) {
String find = whoseTurn.equals("R") ? "B" : "R";
int count = 0;
String c = null;
for (int i = 0; i < emptypeices.length; i++) {
c = emptypeices[i];
if (emptypeices[i] != null) {
int a = Character.getNumericValue(emptypeices[i].charAt(0));
int b = Character.getNumericValue(emptypeices[i].charAt(1));
getCount(a, b, find, whoseTurn);
int resultCount = 0;
// printGrig(grid);
String[] wt = findWhoseTurn(whoseTurn);
for (String l : wt) {
if (l != null) {
getCount(Character.getNumericValue(l.charAt(0)), Character.getNumericValue(l.charAt(1)), find, whoseTurn);
}
}
for (int k = 0; k < 8; k++) {
for (int m = 0; m < 8; m++) {
if (grid[k][m] == whoseTurn) {
resultCount++;
}
}
}
resultCount++;
// System.out.println(resultCount);
if (resultCount > count) {
count = resultCount;
}
grid = createGrid(redPieces, blackPeices);
// System.out.println(c + " is " + count);
// printGrig(grid);
}
}
return count;
} |
59edab09-7a4f-462f-9b65-d64f50191fa7 | public String[] findWhoseTurn(String whoseTurn) {
String[] wt = new String[64];
int c = 0;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (grid[i][j] == whoseTurn) {
wt[c++] = i + "" + j;
}
}
}
return wt;
} |
947acec8-1ea2-446b-8c39-fcd62a9b1485 | private void getCount(int a, int b, String find, String whoseTurn) {
int count = 0;
int x = a, y = b;
// right horizontal
if (++y > -1 && y < 8) {
String con = grid[x][y];
if (grid[x][y].equals(find)) {
int tempCount = 0;
while (y < 8 && grid[x][y].equals(find)) {
y++;
tempCount++;
}
if (grid[x][y].equals(whoseTurn)) {
tempCount++;
for (int j = b + 1; j < y; j++) {
grid[x][j] = whoseTurn;
}
}
count += tempCount;
}
}
// right diagonal bottom
x = a;
y = b;
if (++x < 8 && ++y < 8) {
String con = grid[x][y];
if (grid[x][y].equals(find)) {
int tempCount = 0;
while (x < 8 && y < 8 && grid[x][y].equals(find)) {
y++;
x++;
tempCount++;
}
if (grid[x][y].equals(whoseTurn)) {
tempCount++;
for (int j = a + 1, k = b + 1; j < x && k < y; j++, k++) {
grid[j][k] = whoseTurn;
}
}
count += tempCount;
}
}
// straight bottom
x = a;
y = b;
if (++x < 8) {
if (grid[x][y].equals(find)) {
int tempCount = 0;
while (x < 8 && grid[x][y].equals(find)) {
x++;
tempCount++;
}
if (grid[x][y].equals(whoseTurn)) {
tempCount++;
for (int j = a + 1; j < x; j++) {
grid[j][y] = whoseTurn;
}
}
count += tempCount;
}
}
// left diagonal bottom
x = a;
y = b;
if (++x < 8 && --y > -1) {
String con = grid[x][y];
if (grid[x][y].equals(find)) {
int tempCount = 0;
while (x < 8 && y > -1 && grid[x][y].equals(find)) {
y--;
x++;
tempCount++;
}
if (grid[x][y].equals(whoseTurn)) {
tempCount++;
for (int j = a + 1, k = b - 1; j < x && k > y; j++, k--) {
grid[j][k] = whoseTurn;
}
}
count += tempCount;
}
}
// left Horizontal
x = a;
y = b;
if (--y > -1) {
String con = grid[x][y];
if (grid[x][y].equals(find)) {
int tempCount = 0;
while (y > -1 && grid[x][y].equals(find)) {
y--;
tempCount++;
}
if (grid[x][y].equals(whoseTurn)) {
tempCount++;
for (int j = b - 1; j > y; j--) {
grid[x][j] = whoseTurn;
}
}
count += tempCount;
}
}
// left diagonal top
x = a;
y = b;
if (--x > -1 && --y > -1) {
String con = grid[x][y];
if (grid[x][y].equals(find)) {
int tempCount = 0;
while (x > -1 && y > -1 && grid[x][y].equals(find)) {
y--;
x--;
tempCount++;
}
if (grid[x][y].equals(whoseTurn)) {
tempCount++;
for (int j = a - 1, k = b - 1; j > x && k > y; j--, k--) {
grid[j][k] = whoseTurn;
}
}
count += tempCount;
}
}
// straight top
x = a;
y = b;
if (--x > -1) {
if (grid[x][y].equals(find)) {
int tempCount = 0;
while (x > -1 && grid[x][y].equals(find)) {
x--;
tempCount++;
}
if (grid[x][y].equals(whoseTurn)) {
tempCount++;
for (int j = a - 1; j > x; j--) {
grid[j][y] = whoseTurn;
}
}
count += tempCount;
}
}
// right diagonal top
x = a;
y = b;
if (--x > -1 && ++y < 8) {
String con = grid[x][y];
if (grid[x][y].equals(find)) {
int tempCount = 0;
while (x > -1 && y < 8 && grid[x][y].equals(find)) {
y++;
x--;
tempCount++;
}
if (grid[x][y].equals(whoseTurn)) {
tempCount++;
for (int j = a - 1, k = b + 1; j > x && k < y; j--, k++) {
grid[j][k] = whoseTurn;
}
}
count += tempCount;
}
}
// printGrig(grid);
// return count;
} |
7fedd561-f461-4acb-8ece-b0be3278ed4f | public String[][] createGrid(String[] redPieces, String[] blackPeices) {
String[][] g = new String[8][8];
int c = 0;
for (int r = 0; r < redPieces.length; r++) {
String v = redPieces[r];
g[Character.getNumericValue(v.charAt(1)) - 1][(v.charAt(0) - 'A')] = "R";
}
for (int b = 0; b < blackPeices.length; b++) {
String v = blackPeices[b];
g[Character.getNumericValue(v.charAt(1)) - 1][(v.charAt(0) - 'A')] = "B";
}
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (g[i][j] == null) {
g[i][j] = "-";
emptypeices[c++] = i + "" + j;
}
}
}
// printGrig(g);
return g;
} |
35585076-9ba3-4a84-862e-5108802c1cb8 | public void printGrig(String[][] g) {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
System.out.print(g[i][j]);
System.out.print(" ");
}
System.out.println();
}
System.out.println("=====================");
} |
f43e0e6b-954f-4e72-bc35-97f6646f2817 | public static void main(String[] args) {
Tothello t = new Tothello();
// C2,C3,C4,C5,D4,E4,F2,F3,F4,F5,G6
// B1,E1,G1,C6,H7,G4
// String[] redPieces = { "D1", "D4", "A7" };
// String[] blackPieces = { "B1", "C1", "B2", "C3", "B6" };
/*String[] redPieces = { "C2", "C3", "C4", "C5", "D4", "E4", "F2", "F3", "F4", "F5", "G6" };
String[] blackPieces = { "B1", "E1", "G1", "C6", "H7", "G4" };
t.bestMove(redPieces, blackPieces, "Black");*/
String[] redPieces = { "A1", "B8", "C6", "C8", "D8" };
String[] blackPieces = { "B2", "C2", "C3", "C4", "C5" };
int count = t.bestMove(redPieces, blackPieces, "Red");
System.out.println(count);
} |
de71117d-55c4-429c-9319-94a84d3aaa71 | public static void main(String[] args) {
String param0 = "{\\\\, \\,\\, }";
String[] result = parse(param0);
System.out.println(result.length);
for (String r : result) {
System.out.println(r);
}
} |
a543581a-64f7-4085-b3f1-a88580d6db1f | public static String[] parse(String param0) {
// boolean validareString = validareString(param0);
char[] p = param0.toCharArray();
int count = 1;
List<String> list = new ArrayList<String>();
String pre = "";
boolean escapFlg = false, mainloopFlg = true;
String temp = "";
if (p[0] != '{' || p[p.length - 1] != '}') {
list.add("INVALID");
} else {
while (count <= param0.length() - 2 && mainloopFlg) {
pre = "";
boolean flg = true;
while (flg && count <= param0.length() - 2) {
if (pre.equals("")) {
pre = p[count] + "";
temp += pre;
escapFlg = false;
} else if (pre.equals("") && p[count] == '}') {
pre = "";
temp += pre;
flg = false;
escapFlg = false;
} else if (pre.equals("\\") && (p[count] == ',' || p[count] == '{' || p[count] == '}')) {
if (temp != "") {
temp = temp.substring(0, temp.length() - 1);
}
pre = p[count] + "";
temp += pre;
escapFlg = true;
} else if (pre.equals(",") && p[count] == ' ') {
if (temp == "") {
temp = " ";
} else if (escapFlg) {
pre = " ";
} else {
temp = temp.substring(0, temp.length() - 1);
pre = "";
flg = false;
}
temp += pre;
escapFlg = false;
} else if (pre.equals(",") && p[count] != ' ' && !escapFlg) {
mainloopFlg = false;
temp = "INVALID";
break;
} else if ((pre.equals("{") || pre.equals("}")) && !escapFlg) {
mainloopFlg = false;
temp = "INVALID";
break;
} else {
pre = p[count] + "";
temp += pre;
escapFlg = false;
}
count++;
}
if(temp.equals("INVALID")){
list.clear();
list.add(temp);
}else{
list.add(temp);
}
temp = "";
// count++;
}
if (p[count] == '}' && pre == "") {
list.add("");
}
}
System.out.println(list);
String[] array = new String[list.size()];
list.toArray(array); // fill the array
return array;
} |
73d2460f-9ad3-4248-aadc-f97c2f5cdd5e | private static boolean validareString(String param0) {
if (param0.charAt(0) != '{' || param0.charAt(param0.length() - 1) != '}') {
return false;
} else if (param0.indexOf('{') == 1) {
}
return false;
} |
4116dd2a-8c05-4892-b6ec-d5c1fbc67cca | public static void main(String[] args) {
/*String startPos = "1,0";
String[] pieces = { "2,1", "0,3", "4,3", "5,6", "4,2" };*/
String startPos = "4,1";
String[] pieces = { "2,4", "3,4", "4,4", "5,4", "2,6", "3,6", "4,6", "5,6" };
int result = compute(startPos, pieces);
System.out.println(result);
} |
0d36c64b-ff65-46e7-9610-f8078c0d44a9 | public static int compute(String startPos, String[] p) {
int moveCount = 0;
List<String> pieces = Arrays.asList(p);
moveCount = compute(startPos, pieces, false);
return moveCount;
} |
70e9bc9a-7975-4475-9743-3cb11eca9d31 | private static int compute(String startPos, List<String> pieces, boolean b) {
int moveCount = -1;
int x = Integer.parseInt(startPos.split(",")[0]);
int y = Integer.parseInt(startPos.split(",")[1]);
if (x > 0 && y < 7) {
String checkForBRight = (x + 1) + "," + (y + 1);
String checkForBLeft = (x - 1) + "," + (y + 1);
String checkForEmptyRight = (x + 2) + "," + (y + 2);
String checkForEmptyLeft = (x - 2) + "," + (y + 2);
if (x + 2 <= 7 && y + 2 <= 7 && pieces.contains(checkForBRight) && !pieces.contains(checkForEmptyRight)) {
moveCount = 1;
x = x + 2;
y = y + 2;
int count = compute(x + "," + y, pieces, true);
if (b)
count--;
moveCount += count;
} else if (x - 2 >= 0 && y + 2 <= 7 && pieces.contains(checkForBLeft) && !pieces.contains(checkForEmptyLeft)) {
moveCount = 1;
x = x - 2;
y = y + 2;
int count = compute(x + "," + y, pieces, true);
if (b)
count--;
moveCount += count;
} else if (x + 1 <= 7 && y + 1 <= 7 && !pieces.contains((x + 1) + "," + (y + 1))) {
moveCount = 1;
x = x + 1;
y = y + 1;
int count = compute(x + "," + y, pieces, false);
moveCount += count;
} else if (x - 1 >= 0 && y + 1 <= 7 && !pieces.contains((x - 1) + "," + (y + 1))) {
moveCount = 1;
x = x - 1;
y = y + 1;
int count = compute(x + "," + y, pieces, false);
moveCount += count;
}
} else {
moveCount = 0;
}
return moveCount;
} |
a80d55d0-516a-44c6-89d0-cee78963abe7 | public static void main(String[] args) {
String basePath = "C:\\programs\\GCJ\\TicTacToeTomek\\";
int i = 1;
try {
Scanner sc = new Scanner(new File(basePath + "A-large-practice.in"));
BufferedWriter writer = new BufferedWriter(new FileWriter(basePath + "output.txt"));
int t = sc.nextInt();
sc.nextLine();
String data = "";
int l = 1;
while (sc.hasNextLine()) {
String line = sc.nextLine();
data += line;
if (l == 4) {
String result = solve(data);
writer.write("Case #" + i++ + ": " + result);
writer.newLine();
data = "";
l = 0;
} else {
l++;
}
}
sc.close();
writer.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} |
eb2dd122-eb30-41bb-a7f1-8778e81b3f28 | private static String solve(String data) {
int[] game = new int[16];
boolean complete = true;
int i = 0;
for (int c : data.toCharArray()) {
if (c == '.') {
complete = false;
}
game[i++] = c;
}
for (int[] d : h) {
int count = game[d[0]] + game[d[1]] + game[d[2]] + game[d[3]];
if (count == xwon1 || count == xwon2) {
return "X won";
}
if (count == owon1 || count == owon2) {
return "O won";
}
}
if (!complete) {
return "Game has not completed";
} else {
return "Draw";
}
} |
f90e9516-6e50-4388-8d32-9ede93b924bd | public static void main(String[] args) {
String base = "C:\\programs\\GCJ\\FairAndSquare\\";
String input = base + "input.in";
String output = base + "output.out";
try {
Scanner sc = new Scanner(new FileReader(input));
PrintWriter pw = new PrintWriter(output);
int t = sc.nextInt();
sc.nextLine();
for (int i = 0; i < t; i++) {
String[] line = sc.nextLine().split(" ");
int startRange = Integer.parseInt(line[0]);
int endRange = Integer.parseInt(line[1]);
System.out.println(startRange + " " + endRange);
// System.out.println("Test case " + (c + 1) + "...");
// pw.print("Case #" + (c + 1) + ": ");
// test(sc, pw);
// pw.println();
}
palindrome(1000);
pw.println();
pw.flush();
pw.close();
sc.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
} |
c6566049-587a-4126-9207-f5de9ba69fc3 | private static void palindrome(int range) {
int[] table = new int[range];
int c = 0;
for (int i = 0; i < 10; i++) {
table[c++] = i;
}
for (int i = 11; i < 100; i += 11) {
table[c++] = i;
}
int count = 2;
int n = 100;
for (int i = 101; i < range; i += 10) {
if (i > n * count) {
i = (n * count) + count;
count++;
}
table[c++] = i;
}
int x = 10;
int icount = 100;
count = 2;
n = 1000;
for (int i = 1001; i < range; i += (icount + x)) {
// if (n)
if (i > n * count) {
i = (n * count) + count;
if (count == 10) {
count = 2;
} else {
count++;
}
}
table[c++] = i;
}
for (int i = 0; i < range; i++) {
System.out.print(table[i] + " ");
}
} |
827d14bb-0cb4-46b1-a843-999f1f7efc3f | public static void main(String[] args) {
try {
Scanner sc = new Scanner(new File(basePath + "B-large-practice.in"));
int t = sc.nextInt();
sc.nextLine();
int[][] grid;
int n = 0, m = 0;
int testCase = 1;
while (sc.hasNextLine()) {
String line = sc.nextLine();
String[] nm = separateBySpace(line);
n = Integer.parseInt(nm[0]);
m = Integer.parseInt(nm[1]);
grid = new int[n][m];
for (int i = 0; i < n; i++) {
String[] nmLine = separateBySpace(sc.nextLine());
for (int j = 0; j < m; j++) {
grid[i][j] = Integer.parseInt(nmLine[j]);
}
}
String result = solve(grid, n, m);
System.out.println("Case #" + testCase++ + ": " + result);
/*for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
System.out.print(grid[i][j]);
}
System.out.println();
}
System.out.println("###########");*/
}
sc.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} |
b8b86a67-b8d8-43de-b182-783b3c9f44f7 | private static String solve(int[][] grid, int n, int m) {
boolean rowFlag = true;
boolean colFlag = true;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int spot = grid[i][j];
int max = grid[i][j];
for (int x = 0; x < m; x++) {
if (grid[i][x] > max) {
max = grid[i][x];
}
}
if (max > spot) {
rowFlag = false;
}
max = grid[i][j];
for (int x = 0; x < n; x++) {
if (grid[x][j] > max) {
max = grid[x][j];
}
}
if (max > spot) {
colFlag = false;
}
if (!rowFlag && !colFlag) {
break;
} else {
rowFlag = true;
colFlag = true;
}
}
if (!rowFlag && !colFlag) {
return "NO";
}
}
return "YES";
} |
dcee5d24-82eb-419f-aaf1-34ae750714a4 | private static String[] separateBySpace(String line) {
String[] s = line.split(" ");
return s;
} |
3dc247c5-0f04-4b33-a662-e011c86ff5f8 | public static void main(String[] args) {
String base = "C:\\programs\\GCJ\\FairAndSquare\\";
String input = base + "input.in";
String output = base + "output.out";
try {
Scanner sc = new Scanner(new FileReader(input));
PrintWriter pw = new PrintWriter(output);
int t = sc.nextInt();
sc.nextLine();
while (sc.hasNextLine()) {
}
} catch (Exception ex) {
ex.printStackTrace();
}
} |
a4e34017-de45-4018-b0ba-b853168ddd8d | public Node(Node left, Node right, Node parent, int val, int child) {
this.left = left;
this.right = right;
this.parent = parent;
this.val = val;
this.child = child;
} |
d954a104-006e-416c-9ba1-a41bfe1b56c0 | @Override
public String toString() {
return "Node [ val=" + val + ", child=" + child + "]";
} |
121b2597-6a8d-48ab-9d98-200aaad03cd7 | public static void main(String[] args) {
String base = "C:\\programs\\GCJ\\FullBinaryTree\\";
String input = base + "input.in";
String output = base + "output.out";
Scanner sc = null;
PrintWriter pw = null;
try {
sc = new Scanner(new FileReader(input));
pw = new PrintWriter(output);
int t = sc.nextInt();
sc.nextLine();
int count = 1;
while (t-- > 0) {
int n = sc.nextInt();
HashMap<Integer, java.util.List<Integer>> maps = new HashMap<Integer, java.util.List<Integer>>();
HashMap<Integer, Integer> degree = new HashMap<Integer, Integer>();
for (int i = 0; i < n - 1; i++) {
int[] v = { sc.nextInt(), sc.nextInt() };
for (Integer vi : v) {
if (degree.containsKey(vi)) {
int val = degree.get(vi);
degree.put(vi, val + 1);
} else {
degree.put(vi, 1);
}
}
ArrayList<Integer> list;
if (maps.get(v[0]) != null) {
list = (ArrayList<Integer>) maps.get(v[0]);
} else {
list = new ArrayList<Integer>();
}
list.add(v[1]);
maps.put(v[0], list);
if (maps.get(v[1]) != null) {
list = (ArrayList<Integer>) maps.get(v[1]);
} else {
list = new ArrayList<Integer>();
}
list.add(v[0]);
maps.put(v[1], list);
}
int result = slove(maps, degree, n);
pw.println("Case #" + (count++) + ": " + result);
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (sc != null)
sc.close();
if (pw != null)
pw.close();
}
} |
0b87991d-f0c3-4ced-b2be-65d845a73313 | private static int slove(HashMap<Integer, java.util.List<Integer>> maps, HashMap<Integer, Integer> degree, int n) {
ArrayList<Integer> rootNodes = new ArrayList<Integer>();
for (Entry<Integer, java.util.List<Integer>> set : maps.entrySet()) {
if (set.getValue().size() == 2) {
rootNodes.add(set.getKey());
}
}
int deletedNodeCount = 0;
if (rootNodes.size() > 0) {
deletedNodeCount = n;
for (Integer r : rootNodes) {
Node root = new Node(null, null, new Node(null, null, null, -1, 0), r, 0);
root = makeTree(root, maps);
int count = deleteNode(root, 0);
deletedNodeCount = Math.min(count, deletedNodeCount);
}
}
return deletedNodeCount;
} |
bae0ffe6-bf87-4764-a79f-b6bbba0a2044 | private static int deleteNode(Node root, int count) {
int c = count;
if (root.child == 1) {
if (root.left != null) {
c += root.child;
int g = deleteNode(root.left, c);
c = g;
}
if (root.right != null) {
c += root.child;
int g = deleteNode(root.right, c);
c = g;
}
} else {
if (root.left != null)
c = deleteNode(root.left, c);
if (root.right != null)
c = deleteNode(root.right, c);
}
return c;
} |
9a0b1db2-fed8-49af-8d67-8b3deb1cbbe9 | private static Node makeTree(Node root, HashMap<Integer, java.util.List<Integer>> maps) {
ArrayList<Integer> m = new ArrayList<Integer>(maps.get(root.val));
for (Integer i : m) {
if (root.left == null) {
if (root.parent != null && i != root.parent.val) {
root.left = makeTree(new Node(null, null, root, i, 0), maps);
}
} else {
if (root.parent != null && i != root.parent.val) {
root.right = makeTree(new Node(null, null, root, i, 0), maps);
}
}
}
int child = 0;
if (root.left != null) {
child++;
}
if (root.right != null) {
child++;
}
root.child = child;
return root;
} |
ec2a492f-089f-493d-b51c-d5cac6362770 | public static void main(String[] args) {
String base = "C:\\programs\\GCJ\\ManageYourEnergy\\";
String input = base + "input.in";
String output = base + "output.out";
Scanner sc = null;
PrintWriter pw = null;
try {
sc = new Scanner(new FileReader(input));
pw = new PrintWriter(output);
int t = sc.nextInt();
sc.nextLine();
int count = 1;
while (sc.hasNextLine()) {
String line[] = sc.nextLine().split(" ");
int E = Integer.parseInt(line[0]);
int R = Integer.parseInt(line[1]);
int N = Integer.parseInt(line[2]);
String v[] = sc.nextLine().split(" ");
long totalGain = solve(E, R, N, v);
pw.println("Case #" + (count++) + ": " + totalGain);
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (sc != null)
sc.close();
if (pw != null)
pw.close();
}
} |
984d94c9-3d58-4a4b-b600-20683bc80f45 | private static long solve(int e, int r, int n, String[] v) {
int i = 0;
int currE = e;
long totalGain = 0;
while (i < v.length - 1) {
int next = Integer.parseInt(v[i + 1]);
int curr = Integer.parseInt(v[i]);
if (e == r) {
totalGain += curr * currE;
} else {
int ge = decide(currE, r, curr, next);
totalGain += curr * ge;
currE = currE - ge + r;
if (currE > e)
currE = e;
}
i++;
}
int curr = Integer.parseInt(v[i]);
totalGain += curr * currE;
System.out.println(totalGain);
return totalGain;
} |
2e0cf2e3-74ac-499c-9199-578578091494 | private static int decide(int e, int r, int curr, int next) {
int currE = 0;
if (next > curr) {
currE = e - ((e - r) == 0 ? 1 : e - r);
} else {
currE = e;
}
return currE;
} |
5873d7a1-6ef9-465a-8f20-163071d63f96 | public static void main(String[] args) {
String base = "C:\\programs\\GCJ\\ChargingChaos\\";
String input = base + "input.in";
String output = base + "output.out";
Scanner sc = null;
PrintWriter pw = null;
try {
sc = new Scanner(new FileReader(input));
pw = new PrintWriter(output);
int t = sc.nextInt();
sc.nextLine();
int count = 1;
while (t-- > 0) {
int n = sc.nextInt();
int l = sc.nextInt();
int outlet[] = new int[n];
int device[] = new int[n];
HashSet<Integer> set = new HashSet<Integer>();
for (int i = 0; i < n; i++) {
outlet[i] = Integer.parseInt(sc.nextInt() + "", 2);
}
for (int i = 0; i < n; i++) {
device[i] = Integer.parseInt(sc.nextInt() + "", 2);
set.add(device[i]);
}
int result = l + 1;
for (int i = 0; i < n; i++) {
int shift = outlet[0] ^ device[i];
boolean flg = true;
for (int j = 0; j < n; j++) {
if (flg) {
int value = outlet[j] ^ shift;
if (!set.contains(value)) {
flg = false;
break;
}
}
}
if (flg) {
result = Math.min(Integer.bitCount(shift), result);
}
}
if (result != l + 1) {
pw.println("Case #" + (count++) + ": " + result);
System.out.println(result);
} else {
pw.println("Case #" + (count++) + ": " + "NOT POSSIBLE");
System.out.println("NOT POSSIBLE");
}
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (sc != null)
sc.close();
if (pw != null)
pw.close();
}
} |
a323eca3-d0cc-4f2d-b679-0b1367e6b569 | public static void main(String[] args) {
String base = "C:\\programs\\GCJ\\Lawnmower\\";
String input = base + "input.in";
String output = base + "output.out";
try {
Scanner sc = new Scanner(new FileReader(input));
PrintWriter pw = new PrintWriter(output);
int n = sc.nextInt();
sc.nextLine();
for (int c = 0; c < n; c++) {
System.out.println("Test case " + (c + 1) + "...");
pw.print("Case #" + (c + 1) + ": ");
test(sc, pw);
pw.println();
}
pw.println();
pw.flush();
pw.close();
sc.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
} |
3bbba82b-3f2b-42ff-9b7d-64298ea024bc | private static void test(Scanner sc, PrintWriter pw) {
final int N = sc.nextInt();
final int M = sc.nextInt();
int[][] table = new int[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
table[i][j] = sc.nextInt();
}
}
// Idea : every a_ij must be either the max in their row, or column.
// (and it's enough)
// So we computes the max of every lines and column.
int[] maxr = new int[N];
int[] maxc = new int[M];
for (int i = 0; i < N; i++) {
maxr[i] = 0;
for (int j = 0; j < M; j++) {
if (table[i][j] > maxr[i]) {
maxr[i] = table[i][j];
}
}
}
for (int i = 0; i < M; i++) {
maxc[i] = 0;
for (int j = 0; j < N; j++) {
if (table[j][i] > maxc[i]) {
maxc[i] = table[j][i];
}
}
}
// Finally, if any a_ij is not one of the maxes, we return false.
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
int t = table[i][j];
if (t != maxr[i] && t != maxc[j]) {
pw.print("NO");
return;
}
}
}
pw.print("YES");
} |
1aecec99-d368-453b-b412-5e6e6b72f2f7 | public Pair(long value, int pos) {
this.value = value;
this.pos = pos;
} |
2b7952bd-a347-4a1c-9292-d5f2d443a78c | public int compareTo(Pair other) {
if (this.value < other.value)
return 1;
if (this.value > other.value)
return -1;
return 0;
} |
f16f54e5-da0a-44e0-96c0-14be616c0d89 | @Override
public String toString() {
return "("+value+" "+pos+")";
} |
60278532-784b-4b6d-b19a-bb5630821121 | void solve(Scanner sc, PrintWriter pw) {
long E = sc.nextLong();
long R = sc.nextLong();
if (R > E)
R = E;
int N = sc.nextInt();
long[] v = new long[N];
Pair[] p = new Pair[N];
for (int i = 0; i < N; i++) {
v[i] = sc.nextLong();
p[i] = new Pair(v[i], i);
}
boolean[] was = new boolean[N];
long[] from = new long[N];
long[] to = new long[N];
Arrays.sort(p);
long ans = 0;
for (int i = 0; i < N; i++) {
int pos = p[i].pos;
from[pos] = E;
for (int j = 0; j < pos; j++)
if (was[j])
from[pos] = Math.min(from[pos], to[j] + (pos - j) * R);
to[pos] = 0;
for (int j = pos + 1; j < N; j++)
if (was[j])
to[pos] = Math.max(to[pos], from[j] - (j - pos) * R);
ans += (from[pos] - to[pos]) * p[i].value;
was[pos] = true;
}
pw.println(ans);
} |
3aa8c649-c915-4723-9675-4f7dbf867cc2 | public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(new FileReader(WORK_DIR + "input.in"));
PrintWriter pw = new PrintWriter(new FileWriter(WORK_DIR + "output.in"));
int caseCnt = sc.nextInt();
for (int caseNum = 0; caseNum < caseCnt; caseNum++) {
System.out.println("Processing test case " + (caseNum + 1));
pw.print("Case #" + (caseNum + 1) + ": ");
new ManageYourEnergy().solve(sc, pw);
}
pw.flush();
pw.close();
sc.close();
} |
f324c29d-46c8-4d7f-a53a-dc39cc6d2fd2 | public static void main(String[] Args) throws FileNotFoundException {
Scanner sc = new Scanner(new File("C:\\programs\\GCJ\\ChargingChaos\\input.in"));
PrintWriter out = new PrintWriter(new File("C:\\programs\\GCJ\\ChargingChaos\\output.out"));
// Scanner sc = new Scanner(System.in);
int t = sc.nextInt(), cc = 0;
while (t-- > 0) {
int n = sc.nextInt();
int l = sc.nextInt();
long[] things = new long[n];
long[] things2 = new long[n];
HashSet<Long> hs = new HashSet<Long>();
for (int k = 0; k < n; k++)
things[k] = make(sc.next());
for (int k = 0; k < n; k++) {
things2[k] = make(sc.next());
hs.add(things2[k]);
}
int ans = l + 1;
for (int k = 0; k < n; k++) {
long swit = things[0] ^ things2[k];
boolean good = true;
for (int j = 0; good && j < n; j++)
if (!hs.contains(things[j] ^ swit))
good = false;
if (good)
ans = Math.min(Long.bitCount(swit), ans);
}
if (ans != l + 1)
out.printf("Case #%d: %d%n", ++cc, ans);
else
out.printf("Case #%d: NOT POSSIBLE%n", ++cc);
}
out.close();
} |
6e48aeb3-9309-41dd-8138-095c4676373b | private static long make(String s) {
return Long.parseLong(s, 2);
} |
5a3bc3e6-df6a-4ae4-88c3-d99c076414a4 | @Before
public void _setup() {
mvc = MockMvcBuilders.webAppContextSetup(wac).build();
} |
6162fff8-ad55-4c86-b06d-27273463f499 | public void setBinds(Map<String, Object> binds) {
for (Entry<String, Object> entry : binds.entrySet()) {
builder.bind(entry.getKey(), entry.getValue());
}
} |
73c36809-9a8d-465e-bcc8-cd560d26dfc2 | @PostConstruct
public void activate() throws NamingException {
builder.activate();
} |
b555ed81-f8ca-4f46-81f0-a17a6986305c | @PreDestroy
public void deactivate() {
builder.deactivate();
} |
c8408194-c1ea-4f17-9f33-f8eaf1c32b11 | @Before
public void _setup() {
mvc = MockMvcBuilders.webAppContextSetup(wac).build();
} |
5e004061-7203-4b30-9f5f-18e4b8406932 | public static void main(String[] args) {
String webProject = System.getProperty("user.dir");
List<String> classPath = new ArrayList<>(Arrays.asList(System.getProperty("java.class.path").split(":")));
String tmpPath = classPath.get(0);
if (tmpPath.endsWith("/target/classes")) {
tmpPath = tmpPath.substring(0, tmpPath.length() - "classes".length()) + "test-classes";
classPath.add(0, tmpPath);
webProject = tmpPath.substring(0, tmpPath.length() - "/target/classes".length());
}
StringBuilder buf = new StringBuilder(8192);
nextPath:
for (String path : new LinkedHashSet<>(classPath)) {
int pos = path.lastIndexOf('/');
if (pos == -1) pos = 0;
for (String key : classpathIgnoreKeys) {
if (path.indexOf(key, pos) != -1) continue nextPath;
}
buf.append(';').append(path);
}
PrintStream out = System.out;
final String webClasspath = buf.substring(1);
out.println("项目 classpath:" + webClasspath);
File webapp = new File("src/main/webapp");
if (!webapp.exists()) {
webapp = new File(webProject, "src/main/webapp");
} else {
webProject = webapp.getAbsoluteFile().getParentFile().getParentFile().getParentFile().getAbsolutePath();
}
String baseName = new File(webProject).getName();
if (!baseName.equalsIgnoreCase("web") && baseName.toLowerCase().endsWith("web")
&& !Character.isLetterOrDigit(baseName.charAt(baseName.length() - "web".length() - 1))) {
baseName = baseName.substring(0, baseName.length() - "web".length() - 1);
}
out.println();
out.println("项目 Tomcat配置文件");
out.println("$CATALINA_BASE/conf/Catalina/localhost/" + baseName + ".xml\n");
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<Context docBase=\"" + webapp.getAbsolutePath() + "\" allowLinking=\"true\">\n"
+ " <Loader className=\"org.apache.catalina.loader.VirtualWebappLoader\" virtualClasspath=\"" + webClasspath + "\"/>\n"
+ " <JarScanner scanAllDirectories=\"true\" />\n"
+ " <Resource name=\"jdbc/mysql\" auth=\"Container\" type=\"javax.sql.DataSource\"\n"
+ " maxActive=\"4\" minIdle=\"2\" maxWait=\"3000\"\n"
+ " timeBetweenEvictionRunsMillis=\"14000\"\n"
+ " minEvictableIdleTimeMillis=\"28000\"\n"
+ " username=\"dev\" password=\"dev\" driverClassName=\"com.mysql.jdbc.Driver\"\n"
+ " url=\"jdbc:mysql://host:3306/dev?useUnicode=true&characterEncoding=utf8\"/>\n"
+ "</Context>\n");
} |
31c0b74d-054e-42c0-aeae-2bef01b0efcb | public void addToGradelist(Grades g) {
gradelists.add(g);
} |
6c382dfb-75f4-49f3-b6d1-cabef39c885d | public void emptyGradelist() {
gradelists.clear();
} |
88bfd9f8-677b-4ae4-8529-311224ef2ffa | private List<User> forCourseAttenders() {
if (fc.getExternalContext().getRequestParameterMap().get("id") != null)
return dbh.listCourseParticipants(Integer.parseInt(fc
.getExternalContext().getRequestParameterMap().get("id")));
else
return new ArrayList<User>();
} |
a9ac3c63-528d-45a0-a053-571d5fffbfd5 | public List<Grades> getGradelists() {
return dbh.listGradelist(dbh.getUserId());
} |
1f51adde-1750-4cdd-acbd-bca0a13d5b9c | public Grades getGrade(int userid, int kursid) {
return dbh.getSingleGrade(userid, kursid);
} |
8fce4dea-8377-44d4-9f37-3eea940fe3c0 | public String updateGrades() {
for (int i = 0; i < courseAttenders.size(); i++)
dbh.setSingleGrade(courseAttenders.get(i).get_grade_id(),
courseAttenders.get(i).get_grade_note(), courseAttenders
.get(i).get_grade_bemerkung(),
courseAttenders.get(i).get_grade_fachwissen(),
courseAttenders.get(i).get_grade_sozial(), courseAttenders
.get(i).get_grade_personal(), courseAttenders
.get(i).get_grade_methodisch());
return "gradeeditor.jsf?id="
+ ((fc.getExternalContext().getRequestParameterMap().isEmpty()) ? new ArrayList<User>()
: dbh.listCourseParticipants(Integer.parseInt(fc
.getExternalContext().getRequestParameterMap()
.get("id"))));
} |
4140299b-3bcf-4b8f-92ca-96fbb0940660 | public List<Grades> listUsergrades(int id) {
return dbh.listGradelist(id);
} |
91e5fb92-d36f-4e4e-8c5d-61863dc318dc | public double getAverageGrade(int id, int jahr, String faecherverbund) {
return Math.floor(dbh.getAverageGradeFromVerbund(id, jahr,
faecherverbund) * 100) / 100;
} |
aade0e3a-8a52-45a0-8b1f-2682629054bd | public boolean isBundleChosen(int userid, String bundle){
return dbh.bundleChosen(userid, bundle);
} |
f137a0f4-7ec1-478a-b2aa-ea8e5afb6746 | public void setId(int id) {
this.id = id;
} |
5e4b0680-2a04-49ba-92d1-eaff7b8e0000 | public void setNote(double note) {
this.note = note;
} |
1c453f72-6b74-4292-a7b3-c7856597b616 | public void setBemerkung(String bemerkung) {
this.bemerkung = bemerkung;
} |
2d592c94-f0dd-4e0a-968a-b8fb2e8def6d | public void setUsersid(int usersid) {
this.userid = usersid;
} |
5a276624-485d-4e77-96ab-2be13d07d144 | public void setKursname(String kursname) {
this.kursname = kursname;
} |
05f184ca-d69f-4dd3-97a1-1c90a0611e7b | public int getId() {
return id;
} |
0f257932-e1af-4d93-bcc0-ec7b44e00be4 | public double getNote() {
return note;
} |
d6859634-d2d5-4360-911e-2d5971e8298e | public String getBemerkung() {
return bemerkung;
} |
60e31fe1-13eb-49cc-b471-807c6d8faeec | public int getUsersid() {
return userid;
} |
4bbe9f68-0536-4362-a30d-7f0244eb387d | public String getKursname() {
return kursname;
} |
0fa065c3-6e3b-4d5e-b686-9ba9aaa769cd | public List<User> getCourseAttenders() {
// setCourseAttenders(dbh.listCourseParticipants(Integer.parseInt(fc.getExternalContext().getRequestParameterMap().get("id"))));
return courseAttenders;
} |
93c45080-bc48-4536-aff8-6096a61cb3d2 | public void setCourseAttenders(List<User> courseAttenders) {
this.courseAttenders = courseAttenders;
} |
710b1dfc-5028-47f8-b095-4a894ea25706 | public Grades(int id, double note, String bemerkung, int usersid,
String kursname, int jahr, int tertial, String faecherverbund,
double fachwissen, double sozial, double personal,
double methodisch) {
_id = id;
_note = note;
_bemerkung = bemerkung;
_userid = usersid;
_kursname = kursname;
set_jahr(jahr);
set_tertial(tertial);
set_faecherverbund(faecherverbund);
set_fachwissen(fachwissen);
set_sozial(sozial);
set_personal(personal);
set_methodisch(methodisch);
} |
8fa28558-5dfe-4bac-a24e-c0c63c38f4c9 | public void set_id(int _id) {
this._id = _id;
} |
763d07e8-316e-4fa4-a015-89ecd29fc4be | public void set_note(double _note) {
this._note = _note;
} |
0a48dc37-5b33-4023-ad9c-081931378308 | public void set_bemerkung(String _bemerkung) {
this._bemerkung = _bemerkung;
} |
cfc4dd36-852f-4ba2-b5a3-1c9a3c5091b6 | public void set_usersid(int _usersid) {
this._userid = _usersid;
} |
12f23e4e-e434-4b97-9340-cfb4e6150ca9 | public void set_kursid(String _kursname) {
this._kursname = _kursname;
} |
fe3d635c-45a1-441f-8155-fd15da4cf33b | public int get_id() {
return _id;
} |
833ab5df-000b-49a7-a956-cf16e7c027f2 | public double get_note() {
return _note;
} |
e9cf19d3-816a-4a56-800b-5d7e671788b1 | public String get_bemerkung() {
return _bemerkung;
} |
d1d72d7b-8c20-4f6a-a2f9-aeb910594c2d | public int get_userid() {
return _userid;
} |
9e798680-9a39-4cc9-a2d0-6ffab8b15759 | public String get_kursname() {
return _kursname;
} |
4a129c6a-2c64-490b-8252-95002084f6de | public int get_jahr() {
return _jahr;
} |
972d7bc9-d4ba-4948-8025-b11aa0f5933d | public void set_jahr(int _jahr) {
this._jahr = _jahr;
} |
92a72483-d2f4-46e0-a4b2-8caabfca7b02 | public int get_tertial() {
return _tertial;
} |
2428a002-eb81-4e1a-8676-4bd09b70f352 | public void set_tertial(int _tertial) {
this._tertial = _tertial;
} |
fa371824-b3f4-44f9-9ea4-0d182af05ccc | public String get_faecherverbund() {
return faecherverbund;
} |
70532cc3-009f-4466-9288-630761927121 | public void set_faecherverbund(String faecherverbund) {
this.faecherverbund = faecherverbund;
} |
725e8e2b-1282-4ce6-b7e3-3abfcc1e846b | public Double get_fachwissen() {
return _fachwissen;
} |
939fd266-68ef-4333-9004-3ec3ba3deb48 | public void set_fachwissen(Double _fachwissen) {
this._fachwissen = _fachwissen;
} |
977c1345-9c4b-4c0d-9227-f8034cdce9b0 | public Double get_sozial() {
return _sozial;
} |
7f2d724a-6605-4357-aebe-fed1b054b1ce | public void set_sozial(Double _sozial) {
this._sozial = _sozial;
} |
78c78be4-de47-499b-82b3-388bf0c7a28e | public Double get_personal() {
return _personal;
} |
83f6619c-6673-4fda-8f4b-bd7f08dc8752 | public void set_personal(Double _personal) {
this._personal = _personal;
} |
65cb45b8-3f4c-4652-98e5-374f93dcad34 | public Double get_methodisch() {
return _methodisch;
} |
05220db6-accd-4a40-a04f-e2c9469a4919 | public void set_methodisch(Double _methodisch) {
this._methodisch = _methodisch;
} |
d106cd8c-719f-45b0-ab97-3fa060662b95 | public CourseBean() {
alleKonfessionen = dbh.populateAllConfessions();
} |
76b5b68e-3a29-4024-b87c-f224205b6c50 | public String addCourse() {
if (context.getExternalContext().isUserInRole("lehrer")) {
kurslehrer = dbh.getUserId();
}
dbh.addCourse(name, faecherverbund, kurslehrer, termin,
beschreibung, teilnehmerzahl, sport, konfessionen);
//return kuwasysControllerBean.goCourses();
return "courses";
} |
aaef536c-e03f-4613-9ae1-64ce13db4e7a | public void addToCourses(Course c) {
courses.add(c);
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.