#coding = utf-8 import sys def Cal_NO(a,b): nums=sorted(a,reverse=True) result=nums[b-1] return result if __name__=='__main__': a=[int(i) for i in sys.stdin.readline().split(' ')] b = int(input()) print(Cal_NO(a,b))…
KiKi's K-Number Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3864 Accepted Submission(s): 1715 Problem Description For the k-th number, we all should be very familiar with it. Of course,to…
Data Structure? Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description Data structure is one of the basic skills for Computer Science students, which is a particular way of storing and organizing data…
The k-th Largest Group Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 8353 Accepted: 2712 Description Newman likes playing with cats. He possesses lots of cats in his home. Because the number of cats is really huge, Newman wants to g…
http://acm.hdu.edu.cn/showproblem.php?pid=2639 题目大意是,往背包里赛骨头,求第K优解,在普通01背包的基础上,增加一维空间,那么F[i,v,k]可以理解为前i个物品,放入容量v的背包时,第K优解的值.时间复杂度为O(NVK). Talk is cheap. 看代码吧. import java.util.Scanner; public class BoneCollector { public static void main(String[] sur…
求一组N个数中的第k个最大者,设k=N/2. import java.util.Random; public class K_Max { /** * @param args */ //求第K大的数,保证K大于等于1,小于等于array.length/2哦 public static int TopK(int array[],int K) { int topk[] = new int [K]; for(int i = 0; i<topk.length;i++) topk[i] = array[i]…
在数组a中,a[i]+a[j]=a[k],求a[k]的最大值,a[k]max. 思路:将a中的数组两两相加,组成一个新的数组.并将新的数组和a数组进行sort排序.然后将a数组从大到小与新数组比较,如果当比较到a中第二个数组时,仍无满足条件,则返回最大值不存在. 情况一:不考虑i和j相等的情况.此时新数组长度为a.length*(a.length-1)/2; import java.util.Arrays; public class max { public static void main(S…
快排法求第k大,复杂度为O(n) import com.sun.media.sound.SoftTuning; import java.util.Arrays; import java.util.Random; public class Main { int[] generate(int n) { Random random = new Random(); int[] a = new int[n]; for (int i = 0; i < a.length; i++) { a[i] = rand…
python求100以内素数之和 from math import sqrt # 使用isPrime函数 def isPrime(n): if n <= 1: return False for i in range(2, int(sqrt(n)) + 1): if n % i == 0: return False return True count = 0 for i in range(101): if isPrime(i): count += i print(count) # 单行程序扫描素数…
问题描述:给定一个数组,数组里面元素不重复,求第k个全排列. 算法分析:这道题就是用到取商取模运算. public String getPermutation(int n, int k) { // initialize all numbers ArrayList<Integer> numberList = new ArrayList<Integer>(); for (int i = 1; i <= n; i++) { numberList.add(i); } //第k个,按下…
There is a connected undirected graph with weights on its edges. It is guaranteed that each edge appears in at most one simple cycle. Assuming that the weight of a weighted spanning tree is the sum of weights on its edges, define V(k) V(k) as the wei…
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3718 Accepted Submission(s): 1903 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took par…