描述 http://poj.org/problem?id=3685 一个n*n的矩阵,(i,j)的值为i*i+100000*i+j*j-100000*j+i*j,求第m小的值. Matrix Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 5980 Accepted: 1700 Description Given a N × N matrix A, whose element in the i-th row and j…
描述 http://poj.org/problem?id=3579 给你一串数,共C(n,2)个差值(绝对值),求差值从大到小排序的中值,偶数向下取. Median Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5468 Accepted: 1762 Description Given N numbers, X1, X2, ... , XN, let us calculate the difference of ev…
Description Given a N × N matrix A, whose element × i + j2 - × j + i × j, you are to find the M-th smallest element in the matrix. Input The first line of input is the number of test case. For each test ≤ N ≤ ,) and M( ≤ M ≤ N × N). There is a blank…
Description Given N numbers, X1, X2, ... , XN, let us calculate the difference of every pair of numbers: ∣Xi - Xj∣ ( ≤ i < j ≤ N). We can ) differences through this work, and now your task is to find the median of the differences as quickly as you ca…
传送门 The k-th Largest Group Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 8690 Accepted: 2847 Description Newman likes playing with cats. He possesses lots of cats in his home. Because the number of cats is really huge, Newman wants…
import java.util.Arrays; /* 核心思想:利用快排思想,先假定从大到小排序,找枢纽,枢纽会把大小分开它的两边,当枢纽下标等于k时, 即分了k位在它左边或右边,也就是最大或最小的排到了它的左边或右边了.那么那个枢纽就是要找的第k位了 */ public class SearchNumData { /* n为数组长度 k为要查找的第k大 */ public static int findKth(int[] a, int n, int K) { return findKth(a…
堆排序做的,没有全部排序,找到第k个就结束 public int findKthLargest(int[] nums, int k) { int num = 0; if (nums.length <= 1) return nums[0]; int heapSize = nums.length; //1.构建最大堆 int half = (heapSize-2)/2; for (int i = half;i >= 0;i--) { adjust(nums,heapSize,i); } while…
Dynamic Rankings Time Limit: 10 Seconds Memory Limit: 32768 KB The Company Dynamic Rankings has developed a new kind of computer that is no longer satisfied with the query like to simply find the k-th smallest number of the given N numbers. They…
用快速排序的思想输出数组第k大的元素: #include<iostream> #include<algorithm> using namespace std; //递归实现:返回数组第k大的值.数组下标区间是[begin,end].其中数组假定n个元素,则k的值在区间[1,n]. //能够使用这种方法的前提条件是:n个数不能重复.如果n个数中有重复,那么区间的大小不能保证就是第K大. int findkth(int* arr, int begin, int end, int k)…