No place to hide

Problem Description
It was in a dark daybreak. Dr. Gneh, who was a crazy scientist once trying to dominate the whole humankind by deploying a powerful AI network, had been discovered in a mansion on the grand field outside city of ACM. This time, he got no place to hide.
To help specify the capture operation, let's assume the grand field had nothing else but the mansion on coordinate (Xm, Ym). N interpol elites had been assigned to N different positions around the mansion. The i-th interpol on initial position (Xi, Yi) could move at a maximum speed rate Vi m/s. It was said that Dr. Gneh had invent a rocket motorbike to escape this operation. According to our information, his ride could not change any direction, and ran at a maximum speed rate Vm m/s. For the human future, any failure in this operation was not acceptable. We had to make sure that Dr. Gneh would be captured no matter which way (a particular speed and direction) to flee. It was assumed that our interpols would take action from their positions immediately after Dr. Gneh left his hideout, and be informed of his flee direction at the same time.
Apparently, this was an interesting algorithm problem. Could you tell us whether this operation would be success by our given layout? If yes, what was the minimum number of interpols needed to achieve this success?

Input
There are multiple test cases.
The first line contains a number T (1 ≤ T ≤ 100) indicating the number of test cases.
In each test case, there is an integer N (1 ≤ N ≤ 1000) indicating the number of interpols on the first line.
In the following N+1 lines, describe the specification of Dr. Gneh and our N interpols, and the first line for Dr. Gneh and the next N lines for interpols.
On each line, three float numbers (range [-1e5, 1e5]) represent the speed rate in m/s(which is none negative), x and y coordinate in meters.

Output
For each test case, you only need to output one single number, the minimum number of interpols to capture Dr. Gneh. If it wouldn't be success with all our interpols, output number 0 instead.

Sample Input
2
4
1.0 0 0
1.0 1 0
1.0 0 1
1.0 -1 0
1.0 0 -1
4
2.0 0 0
1.0 1 0
1.0 0 1
1.0 -1 0
1.0 0 -1

Sample Output
2
0

https://ask.csdn.net/questions/670781

leetcode 215

Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.

For example,
Given [3,2,1,5,6,4] and k = 2, return 5.

The basic idea is to use Quick Select algorithm to partition the array with pivot:

Put numbers < pivot to pivot's left
Put numbers > pivot to pivot's right
Then

if indexOfPivot == k, return A[k]
else if indexOfPivot < k, keep checking left part to pivot
else if indexOfPivot > k, keep checking right part to pivot
Time complexity = O(n)

Discard half each time: n+(n/2)+(n/4)..1 = n + (n-1) = O(2n-1) = O(n), because n/2+n/4+n/8+..1=n-1.

Quick Select Solution Code:

public int findKthLargest(int[] nums, int k) {
if (nums == null || nums.length == 0) return Integer.MAX_VALUE;
return findKthLargest(nums, 0, nums.length - 1, nums.length - k);
}

public int findKthLargest(int[] nums, int start, int end, int k) {// quick select: kth smallest
if (start > end) return Integer.MAX_VALUE;

int pivot = nums[end];// Take A[end] as the pivot, 
int left = start;
for (int i = start; i < end; i++) {
    if (nums[i] <= pivot) // Put numbers < pivot to pivot's left
        swap(nums, left++, i);          
}
swap(nums, left, end);// Finally, swap A[end] with A[left]

if (left == k)// Found kth smallest number
    return nums[left];
else if (left < k)// Check right part
    return findKthLargest(nums, left + 1, end, k);
else // Check left part
    return findKthLargest(nums, start, left - 1, k);

}

void swap(int[] A, int i, int j) {
int tmp = A[i];
A[i] = A[j];
A[j] = tmp;

}