这题规律很好找,用最大的跟最小的匹配就好了,但是证明还是挺烦人的。听说是高考题。。。
\(F(n,r) = 1p_1+2p_2+3p_3+\cdots+kp_k\), 其中k是选取的最小值,\(p_k\)表示的是选取最小值的概率。
\[F(n,r) = 1\times\frac{C_{n-1}^{r-1}}{C_n^r} + 2\times\frac{C_{n-2}^{r-1}}{C_n^r} + \cdots + k\times\frac{C_{n-k}^{r-1}}{C_n^r}\, , k = 1,2,\cdots,n-r+1.\]
\[C_n^r\,F(n,r) = 1\times C_{n-1}^{r-1} + 2\times C_{n-2}^{r-1} + \cdots + k\times C_{n-k}^{r-1}\, , k = 1,2,\cdots,n-r+1.\]
令$ G(n,r) = 1C_{n-1}^{r-1} + 2C_{n-2}^{r-1} + \cdots + kC_{n-k}^{r-1} $。
有如下关系
\(C_{n-1}^{r-1} - C_{n-2}^{r-2} = C_{n-2}^{r-1}\)
所以不难得出$G(n, r) = G(n, r-1) + G(n-1,r-1) $ ,发现这个跟组合数有着相同的性质。
\(G(n,1) = 1C_{n-1}^{0} + 2C_{n-2}^{0} + \cdots + kC_{n-k}^{0} = 1+2+3+\cdots+k=1+2+3+\cdots+n = \frac{n(n+1)}{2} = C_{n+1}^{2}\)
\(G(n-1,1) = \frac{n(n-1)}{2}\)
\(G(n-1, 0) = G(n,1) - G(n-1,1) = n\)
\(G(n, 0) = n+1 = C_{n+1}^{1}\)
可以得到\(G(n,r) = C_{n+1}^{r+1}\), 数学归纳法可证
\(F(n,r) = C_{n+1}^{r+1}/C_{n}^{r} = \frac{n+1}{r+1}\)。
所以要\(B_i\)尽量大,\(A_i\)尽量小,问题可解
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <math.h>
using namespace std;
typedef pair<int,int> P;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-9;
const int N = 2e5 + 5;
struct node
{
int id;
int val;
};
node a[N];
int b[N],m;
bool cmp1(node a, node b)
{
return a.val < b.val;
}
bool cmp(int a, int b)
{
return a>b;
}
bool cmp2(node a, node b)
{
return a.id < b.id;
}
int main()
{
scanf("%d", &m);
for(int i = 0; i < m; i++)
{
scanf("%d", &b[i]);
}
sort(b,b+m,cmp);
for(int i = 0; i < m; i++)
{
scanf("%d", &a[i].val);
a[i].id = i;
}
sort(a, a+m, cmp1);
for(int i = 0; i < m; i++)
a[i].val = b[i];
sort(a, a+m, cmp2);
for(int i = 0; i < m; i++)
{
if(i) printf(" ");
printf("%d", a[i].val);
}
printf("\n");
return 0;
}