Let it be X set of integers. describe a data structure with linear size, based on Binary search tree, which supports the following

methods:

1. insertion(a) - insert new integer a to X.

2. search(k) - return the k largest size element in X (the element which exactly k-1 integers are bigger than it).

for each method- you can use at most o(h) memory, when h is the height of the tree.

so, I know how to solve this only with more than o(h) memory for the second method.

I think i need to add here two fields for each node at the tree that contains the number fo sub-trees that are bigger/smaller than it, but i dont know how to proceed from here.

Can you show me the way? ]]>

Quote:

Alex is attending a Halloween party with his girlfriend Silvia. At the party, Silvia spots a giant chocolate bar. If the chocolate can be served as only 1 x 1 sized pieces and Alex can cut the chocolate bar exactly K times, what is the maximum number of chocolate pieces Alex can cut and give Silvia?

The first line contains an integer T, the number of test cases. T lines follow.

Each line contains an integer K

T lines. Each line contains an integer that denotes the maximum number of pieces that can be obtained for each test case.

1<=T<=10

2<=K<=107

Chocolate needed to be served in size of 1 x 1 size pieces.

Alex can't relocate any of the pieces, nor can he place any piece on top of

Code :

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static long Halloween_party(long k){
if(k %2 ==0)
return (k/2)*(k/2);
return (k/2)*(k/2+1);
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int i = 0;i < t;i++){
long k = in.nextInt();
System.out.println(Halloween_party(k));
}
}
}

I can see how it works, and it is great. But how did he work that out? How do you go from looking at the problem to coming up with that answer? What is the process? ]]>

I've been asked to write a code which will calculate the angle at which a batter must strike so that the ball lands 200ft from home plate.

Apparently to solve it I have to use a bissection method in order to find the roots of

R(theta) - 200ft = 0

I really have no idea what this means, if anyone can maybe help get me started, it would be a great help!

Thanks ]]>

can you help?? ]]>