ZOJ - 3278
Description 8g Island has N boys and M girls. Every person has a "charm value". When a boy with charm value t1 and a girl with charm value t2 get together, their "8g value" is t1*t2. Every year the king will choose the Kth greatest number from all the N*M possible 8g values as the lucky number of the year. People on the island knows nothing but 8g, so they ask you to help them find the lucky number. Input The input contains multiply test cases(<= 10). Each test case contains three parts:
Process to the end-of-file. Output For each test case print a single line that contains the lucky number. Sample Input 3 2 3 1 2 3 1 2 2 2 1 1 1 1 1 2 2 4 1 1 1 1 Sample Output 3 1 1 题目大意: 有两个数组,a[n],b[m], 求第K小a[i]*b[j]。 解题思路: 因为N,M的数量级是10^5 。所以不能算出所有的乘积再去找第K大。 那么想到第K大,是一个有序表。那么可以用二分。 首先二分一个答案X.单调性易证。 对于答案X,判断方法是: 判断有多少个比他大的,将B数组排序,枚举A[I],二分a[i]*b[j] >= X。
|
ZOJ 3278 8G Island(二分)
最新推荐文章于 2018-10-16 19:43:02 发布