...
 
Commits (18)
This diff is collapsed.
import lib.UnweightedGraph;
class AllToAllConnected {
public UnweightedGraph G;
public static void main(String[] args) throws Exception {
new AllToAllConnected().run();
}
public void run() throws Exception {
G = new UnweightedGraph();
G.loadFromStdin();
int u = 0;
while (u < G.numberOfNodes() / 256) { /* checking all nodes takes too long */
boolean connectedToAll = true;
int v = 0;
while (v < G.numberOfNodes()) {
connectedToAll = connectedToAll && isConnected(u, v);
v = v + 1;
}
if (connectedToAll) {
System.out.println(1);
} else {
System.out.println(0);
}
u = u + 1;
}
}
public boolean isConnected(int s, int t) {
buildConnectedArray(s);
return scanned[t];
}
public boolean[] scanned;
public void buildConnectedArray(int s) {
scanned = new boolean[G.numberOfNodes()];
int u = 0;
while (u < G.numberOfNodes()) {
scanned[u] = false;
u = u + 1;
}
connectionScan(s);
}
public void connectionScan(int u) {
scanned[u] = true;
int e = G.firstEdge(u);
while (e < G.firstInvalidEdge(u)) {
int v = G.edgeTarget(e);
if (!scanned[v] && u != v) {
connectionScan(v);
}
e = e + 1;
}
}
}
\ No newline at end of file
class FieldInit {
public int i;
public FieldInit f;
public boolean b;
public static void main(String[] args) {
FieldInit f = new FieldInit();
System.out.println(f.i);
if(!f.b) {
System.out.println(1);
}
if(f.f == null) {
System.out.println(2);
}
}
}
import lib.MinHeap;
class MinHeapTest {
public static void main(String[] args) {
MinHeap heap = new MinHeap();
/* populate it */
heap.insert(60);
System.out.println(heap.minKey());
heap.insert(10);
System.out.println(heap.minKey());
heap.insert(5);
System.out.println(heap.minKey());
heap.insert(20);
System.out.println(heap.minKey());
/* now make it empty again */
System.out.println(heap.deleteMin());
System.out.println(heap.deleteMin());
System.out.println(heap.deleteMin());
System.out.println(heap.deleteMin());
/* now do both */
heap.insert(100);
System.out.println(heap.deleteMin());
heap.insert(100);
heap.insert(90);
System.out.println(heap.deleteMin());
heap.insert(80);
heap.insert(70);
System.out.println(heap.deleteMin());
System.out.println(heap.deleteMin());
System.out.println(heap.deleteMin());
/* test decreaseKey */
int handle1 = heap.insert(100);
int handle2 = heap.insert(50);
heap.decreaseKey(handle2, 40);
heap.decreaseKey(handle1, 10);
System.out.println(heap.deleteMin());
System.out.println(heap.deleteMin());
}
}
\ No newline at end of file
......@@ -6,7 +6,7 @@ class B {
i[x] = (x = x + 1);
}
x = -1;
while(x < 4) {
while(x < 3) {
System.out.println(i[(x = x + 1)]);
}
......
import lib.BooleanUtils;
class Test {
public static void main(String[] args) {
BooleanUtils bu = new BooleanUtils();
boolean b1 = 0 == 0;
boolean b2 = 0 != 0;
boolean b3 = !true;
boolean b4 = !!!true == true;
bu.println(b1);
bu.println(b2);
bu.println(b3);
bu.println(b4);
}
}
\ No newline at end of file
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\ No newline at end of file
This diff is collapsed.
class Math {
public int pow(int v, int exp){
if (exp < 0){
return 1 / pow(v, -exp);
} else if (exp == 0){
return 1;
} else {
int ret = 1;
while (exp > 0){
if (exp % 2 == 0){
v = v * v;
exp = exp / 2;
} else {
ret = ret * v;
exp = exp - 1;
}
}
return ret;
}
}
public int factorial(int val){
int ret = 1;
int sign = signum(val);
if (val < 0){
val = -val;
}
if (val == 0){
return 1;
}
while (val > 0){
ret = ret * val;
val = val - 1;
}
return ret * sign;
}
public int min(int s, int t){
if (s < t){
return s;
}
return t;
}
public int max(int s, int t){
if (s > t){
return s;
}
return t;
}
public int lengthInChars(int num){
int len = 1;
if (num < 0){
len = len + 1;
num = -num;
}
while (num > 10){
num = num / 10;
len = len + 1;
}
return len;
}
public int signum(int num){
if (num == 0){
return 0;
}
if (num < 0){
return -1;
}
return 1;
}
public int abs(int num){
if (num < 0){
return -num;
}
return num;
}
}
/*
Adapted from the following source:
The Computer Language Benchmarks Game
http://benchmarksgame.alioth.debian.org/
contributed by Jarkko Miettinen
*/
class binarytrees {
public int minDepth;
public static void main(String[] args){
new binarytrees().init().run(19);
}
public binarytrees init(){
minDepth = 4;
return this;
}
public void run(int n){
int maxDepth = 0;
if (minDepth + 2 > n){
maxDepth = minDepth + 2;
} else {
maxDepth = n;
}
int stretchDepth = maxDepth + 1;
int check = bottomUpTree(0,stretchDepth).itemCheck();
/*System.out.println("stretch tree of depth "+stretchDepth+"\t check: " + check);*/
System.out.println(stretchDepth);
System.out.println(check);
TreeNode longLivedTree = bottomUpTree(0,maxDepth);
int depth = minDepth;
while (depth <= maxDepth){
int iterations = new Math().pow(2, maxDepth - depth + minDepth);
check = 0;
int i = 1;
while (i <= iterations){
check = check + (bottomUpTree(i,depth)).itemCheck();
check = check + (bottomUpTree(-i,depth)).itemCheck();
i = i + 1;
}
/*System.out.println((iterations*2) + "\t trees of depth " + depth + "\t check: " + check);*/
System.out.println(iterations * 2);
System.out.println(depth);
System.out.println(check);
depth = depth + 2;
}
/*System.out.println("long lived tree of depth " + maxDepth + "\t check: "+ longLivedTree.itemCheck());*/
System.out.println(maxDepth);
System.out.println(longLivedTree.itemCheck());
}
public TreeNode bottomUpTree(int item, int depth){
if (depth>0){
return new TreeNode().init2(
bottomUpTree(2*item-1, depth-1)
, bottomUpTree(2*item, depth-1)
, item
);
}
else {
return new TreeNode().init(item);
}
}
}
class TreeNode {
public TreeNode left;
public TreeNode right;
public int item;
public TreeNode init(int item){
this.item = item;
return this;
}
public TreeNode init2(TreeNode left, TreeNode right, int item){
this.left = left;
this.right = right;
this.item = item;
return this;
}
public int itemCheck(){
if (left==null) return item;
else return item + left.itemCheck() - right.itemCheck();
}
}
20
-1
1048576
4
-1048576
262144
6
-262144
65536
8
-65536
16384
10
-16384
4096
12
-4096
1024
14
-1024
256
16
-256
64
18
-64
19
-1
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\ No newline at end of file
This diff is collapsed.
/*
* conways_game_of_life.mj -- Plays Conway's Game of Life.
*
* This is a simulator for Conway's Game of Life [1]. To get the maximum fun
* out of it, you need a video terminal that understands ANSI escape sequences.
* Then, piping the output of this program through a filter as explained in
* `hello_world.mj` will show you a fancy animation of the game. If you cannot
* get access to a terminal (emulator) that is capable of this, you can set the
* variable `HAVE_ANSI` near the beginning of `main` to `false`. Then, the
* output will not use ANSI escape codes but look rather sad. You'll probably
* also want to reduce the iteration count in this case. Here are all
* variables that you might want to tweak.
*
* - `HAVE_ANSI` -- whether ANSI escape codes are supported by the terminal
* - `LINES` -- number of lines available on the terminal
* - `COLUMNS` -- number of columns available on the terminal
* - `ITERATIONS` -- number of iterations to play
* - `RANDOM_SEED` -- random seed for initializing the game
*
* Since MiniJava has no way to suspend, this program deliberately uses an
* inefficient strategy to print the output (knowing that terminals are
* *really* slow at interpreting ANSI escape codes). This means that the
* program will eat all your CPU while it is running. The update rate is about
* alright on my PC but if your computer is much faster or much slower, you
* might not enjoy the animation very much.
*
* [1] https://en.wikipedia.org/wiki/Conway's_Game_of_Life
*
*/
class CWGOLMain {
public static void main(String[] args) throws Exception {
boolean HAVE_ANSI = true;
int LINES = 24;
int COLUMNS = 80;
int ITERATIONS = 50000;
int RANDOM_SEED = System.in.read();
Game g = new Game();
g.init(LINES - 2, COLUMNS / 2 - 1);
LCG lcg = new LCG();
lcg.init(RANDOM_SEED);
int i = 0;
while (i < g.rows()) {
int j = 0;
while (j < g.columns()) {
if (lcg.next() % 8 == 0) {
g.set(i, j);
}
j = j + 1;
}
i = i + 1;
}
BoardPrinter bp = new BoardPrinter();
bp.init();
if (HAVE_ANSI) {
bp.fancyInit(g);
}
int k = 0;
while (k < ITERATIONS) {
if (k == 1 || k + 1 == ITERATIONS) {
if (HAVE_ANSI) {
bp.fancyPrintBoard(g, k);
} else {
bp.printBoard(g, k);
}
}
g.next();
k = k + 1;
}
if (HAVE_ANSI) {
bp.fancyFini();
}
}
}
class BoardPrinter {
public void init() {
_M_digitsBuffer = new int[10];
}
public void printBoard(Game game, int iteration) {
_M_printInt(iteration);
System.out.println(10);
_M_printRule(game.columns());
int i = 0;
while (i < game.rows()) {
int j = 0;
System.out.println(124);
while (j < game.columns()) {
if (game.get(i, j)) {
System.out.println(42);
} else {
System.out.println(32);
}
j = j + 1;
}
System.out.println(124);
System.out.println(10);
i = i + 1;
}
_M_printRule(game.columns());
System.out.println(10);
}
public void fancyInit(Game game) {
int k;
_M_ansiDectcem(false);
_M_ansiSgr(7, 0);
_M_ansiEd(2);
_M_ansiCup(1, 1);
System.out.println(43);
k = 0;
while (k < 2 * game.columns()) {
System.out.println(45);
k = k + 1;
}
System.out.println(43);
_M_ansiCup(2 + game.rows(), 1);
System.out.println(43);
k = 0;
while (k < 2 * game.columns()) {
System.out.println(45);
k = k + 1;
}
System.out.println(43);
k = 0;
while (k < game.rows()) {
_M_ansiCup(2 + k, 1);
System.out.println(124);
_M_ansiCup(2 + k, 2 + 2 * game.columns());
System.out.println(124);
k = k + 1;
}
}
public void fancyFini() {
_M_ansiDectcem(true);
_M_ansiSgr(9, 9);
_M_ansiEd(2);
_M_ansiCup(1, 1);
}
public void fancyPrintBoard(Game game, int iteration) {
int i;
int j;
_M_ansiCup(1, 10);
_M_ansiSgr(7, 0);
_M_printInt(iteration);
i = 0;
while (i < game.rows()) {
j = 0;
while (j < game.columns()) {
_M_ansiCup(2 + i, 2 + 2 * j);
if (game.get(i, j)) {
_M_ansiSgr(9, 2);
} else {
_M_ansiSgr(9, 0);
}
System.out.println(32);
System.out.println(32);
j = j + 1;
}
i = i + 1;
}
}
public int[] _M_digitsBuffer;
public void _M_printRule(int columns) {
System.out.println(43);
while (columns > 0) {
System.out.println(45);
columns = columns - 1;
}
System.out.println(43);
System.out.println(10);
}
public void _M_ansiSgr(int fg, int bg) {
_M_ansiCsi();
System.out.println(51);
System.out.println(48 + fg);
System.out.println(109);
_M_ansiCsi();
System.out.println(52);
System.out.println(48 + bg);
System.out.println(109);
}
public void _M_ansiEd(int code) {
_M_ansiCsi();
System.out.println(48 + code);
System.out.println(74);
}
public void _M_ansiEl(int code) {
_M_ansiCsi();
System.out.println(48 + code);
System.out.println(75);
}
public void _M_ansiCup(int row, int col) {
_M_ansiCsi();
_M_printInt(row);
System.out.println(59);
_M_printInt(col);
System.out.println(72);
}
public void _M_ansiDectcem(boolean show) {
_M_ansiCsi();
System.out.println(63);
System.out.println(50);
System.out.println(53);
if (show) {
System.out.println(104);
} else {
System.out.println(108);
}
System.out.println(10);
}
public void _M_ansiCsi() {
System.out.println(27);
System.out.println(91);
}
public void _M_printInt(int n) {
if (n == 0) {
System.out.println(48);
return;
}
int i = 0;
while (n > 0) {
_M_digitsBuffer[i] = n % 10;
n = n / 10;
i = i + 1;
}
while (i > 0) {
System.out.println(48 + _M_digitsBuffer[i - 1]);
i = i - 1;
}
}
}
class Game {
public void init(int rows, int columns) {
int size = rows * columns;
_M_rows = rows;
_M_columns = columns;
_M_active_board = new boolean[size];
_M_passive_board = new boolean[size];
int idx = 0;
while (idx < size) {
_M_active_board[idx] = false;
_M_passive_board[idx] = false;
idx = idx + 1;
}
}
public int rows() {
return _M_rows;
}
public int columns() {
return _M_columns;
}
public boolean get(int i, int j) {
return _M_active_board[_M_getIndex(i, j)];
}
public void set(int i, int j) {
_M_active_board[_M_getIndex(i, j)] = true;
}
public void next() {
int i = 0;
while (i < _M_rows) {
int j = 0;
while (j < _M_columns) {
int index = _M_getIndex(i, j);
int neighbours = _M_liveNeighbours(i, j);
if ((neighbours < 2) || (neighbours > 3)) {
_M_passive_board[index] = false;
} else if (neighbours == 3) {
_M_passive_board[index] = true;
} else {
_M_passive_board[index] = _M_active_board[index];
}
j = j + 1;
}
i = i + 1;
}
_M_swapBuffers();
}
public int _M_rows;
public int _M_columns;
public boolean[] _M_active_board;
public boolean[] _M_passive_board;
public int _M_getIndex(int i, int j) {
i = (_M_rows + i) % _M_rows;
j = (_M_columns + j) % _M_columns;
return i * _M_columns + j;
}
public int _M_liveNeighbours(int i, int j) {
int count = 0;
if (get(i - 1, j - 1)) { count = count + 1; }
if (get(i - 1, j )) { count = count + 1; }
if (get(i - 1, j + 1)) { count = count + 1; }
if (get(i, j - 1)) { count = count + 1; }
if (get(i, j + 1)) { count = count + 1; }
if (get(i + 1, j - 1)) { count = count + 1; }
if (get(i + 1, j )) { count = count + 1; }
if (get(i + 1, j + 1)) { count = count + 1; }
return count;
}
public void _M_swapBuffers() {
boolean[] temp = _M_active_board;
_M_active_board = _M_passive_board;
_M_passive_board = temp;
}
}
class LCG {
public void init(int seed) {
_M_a = 5;
_M_c = 11;
_M_m = 7901;
_M_state = seed % _M_m;
}
public int next() {
int prev = _M_state;
_M_state = (_M_a * prev + _M_c) % _M_m;
return prev;
}
public int _M_a;
public int _M_c;
public int _M_m;
public int _M_state;
}
class Math {
public int pow(int v, int exp){
if (exp < 0){
return 1 / pow(v, -exp);
} else if (exp == 0){
return 1;
} else {
int ret = 1;
while (exp > 0){
if (exp % 2 == 0){
v = v * v;
exp = exp / 2;
} else {
ret = ret * v;
exp = exp - 1;
}
}
return ret;
}
}
public int factorial(int val){
int ret = 1;
int sign = signum(val);
if (val < 0){
val = -val;
}
if (val == 0){
return 1;
}
while (val > 0){
ret = ret * val;
val = val - 1;
}
return ret * sign;
}
public int min(int s, int t){
if (s < t){
return s;
}
return t;
}
public int max(int s, int t){
if (s > t){
return s;
}
return t;
}
public int lengthInChars(int num){
int len = 1;
if (num < 0){
len = len + 1;
num = -num;
}
while (num > 10){
num = num / 10;
len = len + 1;
}
return len;
}
public int signum(int num){
if (num == 0){
return 0;
}
if (num < 0){
return -1;
}
return 1;
}
public int abs(int num){
if (num < 0){
return -num;
}
return num;
}
}
/*
Adapted from the following source:
The Computer Language Benchmarks Game
http://shootout.alioth.debian.org/
contributed by Isaac Gouy
converted to Java by Oleg Mazurov
*/
class fannkuchredux {
public int maxFlipsCount;
public void fannkuch(int n) {
int[] perm = new int[n];
int[] perm1 = new int[n];
int[] count = new int[n];
maxFlipsCount = 0;
int permCount = 0;
int checksum = 0;
int i = 0;
while (i < n){
perm1[i] = i;
i = i + 1;
}
int r = n;
while (true) {
while (r != 1){ count[r-1] = r; r = r - 1; }
i = 0;
while (i < n){
perm[i] = perm1[i];
i = i + 1;
}
int flipsCount = 0;
int k = 0;
while ( !((k=perm[0]) == 0) ) {
int k2 = (k+1) / 2;
int j = 0;
while (j < k2){
int temp = perm[j]; perm[j] = perm[k-j]; perm[k-j] = temp;
j = j + 1;
}
flipsCount = flipsCount + 1;
}
maxFlipsCount = new Math().max(maxFlipsCount, flipsCount);
if (permCount % 2 == 0){
checksum = checksum + flipsCount;
} else {
checksum = checksum - flipsCount;
}
/* Use incremental change to generate another permutation */
boolean doBreak = false;
while (!doBreak) {
if (r == n) {
System.out.println( checksum );
return;
}
int perm0 = perm1[0];
int l = 0;
while (l < r) {
int j = l + 1;
perm1[l] = perm1[j];
l = j;
}
perm1[r] = perm0;
count[r] = count[r] - 1;
if (count[r] > 0) doBreak = true;
else r = r + 1;
}
permCount = permCount + 1;
}
}
public static void main(String[] args){
fannkuchredux fk = new fannkuchredux();
fk.fannkuch(11);
System.out.println(fk.maxFlipsCount);
}
}
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\ No newline at end of file
120
31839**4
-1740920015
-2013+-(((((((99507**4)*-(((72438*96575)*((-((67322+46322)*56165)*11280)+-4904))**6))+89334)+0758)+-(--86695!+-25)!)%38997)**3)
1695610786
(62104+45589)+-(((49052+3802)+-54717)*(((88999-93662)*88221)**7))
138680
7127--8720
7495
(((17638+-74979)**4)**7)**8
0
(((53659---((-(-(-(-59332!**8)*-(27446*82134))*-3493!)+((((---68524+71120)**8)-82078)%71767))**7))+--28989!!)-(-(-(1474!*(--35089**2))**9)!-73100))**6
-752474543
--88302/3825
3
(--35187+(((44737-47902)**3)!-60266))+87358
97325
-34737!----(20220+--15712)
23953
-6536**5
1147628544
This diff is collapsed.
class Bools {
public boolean b;
public static void main(String[] args) {
Bools b = new Bools();
if(!b.b) {
System.out.println(1);
}
b.b = false || true;
if(!b.b) {
System.out.println(2);
}
b.b = false || false;
if(!b.b) {
System.out.println(3);
}
b.b = true || true;
if(!b.b) {
System.out.println(4);
}
b.b = true || false;
if(!b.b) {
System.out.println(5);
}
b.b = false && true;
if(!b.b) {
System.out.println(6);
}
b.b = true && true;
if(!b.b) {
System.out.println(7);
}
b.b = false && false;
if(!b.b) {
System.out.println(8);
}
b.b = true && false;
if(!b.b) {
System.out.println(9);
}
}
}
class Test {
public static void main(String[] args) throws Exception {
System.out.println(System.in.read());
System.out.println(System.in.read()); /* should return -1 */
}
}
class EvaluationOrder {
public int i;
public EvaluationOrder setI(int i) {
this.i = i + 1;
System.out.println(this.i);
return this;}
public static void main(String[] args) {
EvaluationOrder e = new EvaluationOrder();
int[] arr = new int[3];
arr[e.setI(-1).i] = e.setI(e.setI(2).i).i + 4;
System.out.println(arr[0]);
}
}
\ No newline at end of file
class EvaluationOrder {
public int i;
public EvaluationOrder setI(int i) {
this.i = i + 1;
System.out.println(this.i);
return this;}
public static void main(String[] args) {
EvaluationOrder e = new EvaluationOrder();
int[] arr = new int[3];
arr[e.setI(-1).i] = e.setI(e.setI(2).i).i + e.setI(1).i * e.setI(2).i + e.setI(3).i / e.setI(4).i % e.setI(5).i;
System.out.println(arr[0]);
}
}
\ No newline at end of file
class A {
public int i;
public static void main(String[] args) {
A a = new A();
a.i = 0;
System.out.println(a.effect(a).i);
int[] arr = new int[42];
arr[arr[0] = 10] = 42;
System.out.println(arr[0]);
System.out.println(arr[10]);
int x;
arr[x = 11] = x;
System.out.println(arr[11]);
a.effect(a.effect(a.effect(a)));
}
public A effect(A a) {
System.out.println(a.i);
A result = new A();
result.i = a.i + 1;;
return result;
}
}
class If {
public static void main(String[] args) {
boolean b = true;
if (b) {
b = false;
if (b) {
System.out.println(1);
} else {
if (!b) {
if (b) {
System.out.println(2);
} else {
System.out.println(3);
}
} else {
b = true;
if (b) {
System.out.println(4);
} else {
System.out.println(5);
}
}
}
} else {
System.out.println(6);
}
}
}
\ No newline at end of file
class IntMin {
public static void main(String[] args) {
System.out.println(1 / 2);
System.out.println(6 / 3);
System.out.println(-6 / 3);
System.out.println(6 / -3);
System.out.println(-6 / -3);
System.out.println(-2147483648 * -1);
System.out.println(-2147483648 / -1);
}
}
\ No newline at end of file
class Test {
public static void main(String[] args) {
int INT_MAX = 2147483647;
int INT_MIN = -2147483648;
System.out.println(INT_MAX + 1);
System.out.println(INT_MIN - 1);
System.out.println(INT_MAX * 2);
System.out.println(INT_MIN * 2);
System.out.println(INT_MAX * -1);
System.out.println(INT_MIN * -1);
System.out.println(INT_MAX / 1);
System.out.println(INT_MIN / 1);
System.out.println(INT_MAX / -1);
System.out.println(INT_MIN / -1);
System.out.println(INT_MAX / INT_MAX);
System.out.println(INT_MIN / INT_MIN);
System.out.println(INT_MAX / INT_MIN);
System.out.println(INT_MIN / INT_MAX);
System.out.println(INT_MAX % 1);
System.out.println(INT_MIN % 1);
System.out.println(INT_MAX % -1);
System.out.println(INT_MIN % -1);
System.out.println(INT_MAX % INT_MAX);
System.out.println(INT_MIN % INT_MIN);
System.out.println(INT_MAX % INT_MIN);
System.out.println(INT_MIN % INT_MAX);
}
}
\ No newline at end of file
package lib;
public class MinHeap {
public MinHeapEntry[] heap;
public int heapSize;
public int heapCapacity;
public int insert(int key) {
int handle = heapSize;
MinHeapEntry entry = new MinHeapEntry();
entry.key = key;
entry.handle = handle;
if (heapSize == heapCapacity) growHeap();
heap[handle] = entry;
heapSize = heapSize + 1;
siftDown(handle);
return handle;
}
public void decreaseKey(int handle, int key) {
/* find our element */
int i = 0;
boolean found = false;
while (i < heapSize && !found) {
if (heap[i].handle == handle) {
found = true;
}
i = i + 1;
}
i = i - 1;
/* then change the key and restore heap property */
heap[i].key = key;
siftUp(i);
}
public int minKey() {
return heap[0].key;
}
public int deleteMin() {
int key = heap[0].key;
int i = 1;
while (i < heapSize) {
heap[i - 1] = heap[i];
i = i + 1;
}
heapSize = heapSize - 1;
if (heapSize > 0) siftUp(0);
return key;
}
/* private methods */
public void growHeap() {
int newCapacity = 0;
if (heapCapacity == 0) {
newCapacity = 1;
} else {
newCapacity = heapCapacity * 2;
}
MinHeapEntry[] newHeap = new MinHeapEntry[newCapacity];
int i = 0;
while (i < heapCapacity) {
newHeap[i] = heap[i];
i = i + 1;
}
heapCapacity = newCapacity;
heap = newHeap;
}
public void siftUp(int pos) {
int currentKey = heap[pos].key;
int lhsChild = 2 * pos + 1;
int rhsChild = 2 * pos + 2;
if (rhsChild < heapSize) {
int lhsKey = heap[lhsChild].key;
int rhsKey = heap[rhsChild].key;
if (lhsKey < currentKey || rhsKey < currentKey) {
int swapPosition = rhsChild;
if (lhsKey < rhsKey) {
swapPosition = lhsChild;
}
swap(pos, swapPosition);
siftUp(swapPosition);
}
return;
}
if (lhsChild < heapSize) {
if (heap[pos].key > heap[lhsChild].key) {
swap(pos, lhsChild);
siftUp(lhsChild);
}
}
}
public void siftDown(int pos) {
if (pos <= 0) return;
int parentPos = (pos - 1) / 2;
if (heap[parentPos].key > heap[pos].key) {
swap(parentPos, pos);
siftDown(parentPos);
}
}
public void swap(int a, int b) {
MinHeapEntry tmp = heap[a];
heap[a] = heap[b];
heap[b] = tmp;
}
}
class MinHeapEntry {
public int handle;
public int key;
}
\ No newline at end of file
package lib;
public class UnweightedGraph {
public int firstEdge(int u) {
return nodes[u];
}
public int firstInvalidEdge(int u) {
return nodes[u + 1];
}
public int edgeTarget(int e) {
return edges[e];
}
public int numberOfNodes() {
return numberOfNodes;
}
public int numberOfEdges() {
return numberOfEdges;
}
/**
* Reads unweighted graphs in METIS format.
*/
public void loadFromStdin() throws Exception {
numberOfNodes = readIntFromStdin();
numberOfEdges = readIntFromStdin() * 2;
readIntFromStdin(); /* new line */
nodes = new int[numberOfNodes + 1];
edges = new int[numberOfEdges];
int u = 0;
int e = 0;
while (u < numberOfNodes) {
int v;
while ((v = readIntFromStdin()) != -1) {
edges[e] = v - 1;
e = e + 1;
}
u = u + 1;
nodes[u] = e;
}
}
/* private */
public int numberOfNodes;
public int[] nodes;
public int numberOfEdges;
public int[] edges;
public boolean endedOnNewLine;
/**
* @return the next integer or a negative integer if a new line character is read.
*/
public int readIntFromStdin() throws Exception {
if (endedOnNewLine) {
endedOnNewLine = false;
return -1;
}
int ch;
while (((ch = System.in.read()) < 48 || ch > 57) && ch != 10);
if (ch == 10) return -1;
int num = 0;
while (48 <= ch && ch <= 57) {
num = num * 10 + (ch - 48);
ch = System.in.read();
}
if (ch == 10) endedOnNewLine = true;
return num;
}
}
\ No newline at end of file
import lib.BooleanUtils;
class Test {
public static void main(String[] args) {
BooleanUtils bu = new BooleanUtils();
a a = new a();
a b = new a();
bu.println(a == a);
bu.println(a != a);
bu.println(b == b);
bu.println(b != b);
bu.println(a == b);
bu.println(a != b);
bu.println(a == null);
bu.println(a != null);
bu.println(null == b);
bu.println(null != b);
}
}
class a {
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ class A {
public int loopy_1() {
int i = 3;
while (i < 5) { return i; }
return i;
}
public static void main(String[] args) {
......
class A {
public int i;
class SimplePrint {
public static void main(String[] args) {
A a = null;
int i = a.i;
System.out.println(42);
}
}
\ No newline at end of file
class SimpleWriteFlush {
public static void main(String[] args) {
System.out.write(42);
System.out.flush();
}
}
\ No newline at end of file
import lib.BooleanUtils;
class Test {
public static void main(String[] args) {
BooleanUtils bu = new BooleanUtils();
int[] a = new int[0];
int[] b = new int[0];
bu.println(a == a);
bu.println(a != a);
bu.println(b == b);
bu.println(b != b);
bu.println(a == b);
bu.println(a != b);
bu.println(a == null);
bu.println(a != null);
bu.println(null == b);
bu.println(null != b);
}
}
\ No newline at end of file
class A{}
class Foo {
public static void main(String[] args) {
System.out.flush(new A());
}
}
This diff is collapsed.
This diff is collapsed.
class Foo {
public static void main(String[] args) {
boolean a = System.in.read();
}
}
This diff is collapsed.
This diff is collapsed.