void solve(int caseNum) { chars = in.next().toCharArray(); Node tree = new Node(); tree.stretch(); System.out.println(caseNum); System.out.print(tree); }
public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner in = new Scanner(System.in); int N = in.nextInt(); Node[] nodes = new Node[N]; for (int i = 0; i < N; i++) { nodes[i] = new Node(i + 1); } for (int i = 0; i < N; i++) { int a = in.nextInt(); int b = in.nextInt(); Node n = nodes[i]; if (a != -1) n.left = nodes[a - 1]; if (b != -1) n.right = nodes[b - 1]; } int T = in.nextInt(); for (int i = 0; i < T; i++) { int K = in.nextInt(); swap(nodes[0], K, 1); Inorder(nodes[0]); System.out.println(""); } }
static void swap(Node root, int K, int C) { if (root == null) return; if ((C % K) == 0) { Node tmp = root.right; root.right = root.left; root.left = tmp; } C = C + 1; swap(root.left, K, C); swap(root.right, K, C); }
void generate() { if (c == null) { stringBuf[x[0]][x[1]] = v; for (int i = 0; i < 2; i++) { for (int j = 0; j < dim[i]; j++) { x[i]++; char current = stringBuf[x[0]][x[1]]; if (current == '-' || current == '|') stringBuf[x[0]][x[1]] = '*'; else stringBuf[x[0]][x[1]] = walls[i]; } x[i] -= dim[i]; } } else { for (Node child : c) { child.generate(); for (int i = 0; i < 2; i++) x[i] += (v == i ? child.dim[i] : 0); } for (Node child : c) for (int i = 0; i < 2; i++) x[i] -= (v == i ? child.dim[i] : 0); } }
void stretch() { if (c == null) return; for (Node child : c) { if (dim[1 - v] > child.dim[1 - v]) { int len = dim[1 - v]; child.dim[1 - v] = len; if (child.c != null) { int ea = len / child.c.size(); for (Node cc : child.c) { cc.dim[1 - v] = ea; if (len > ea * child.c.size()) { cc.dim[1 - v]++; len--; } cc.stretch(); } } } child.stretch(); } }