Description
定义F(n,k)为从{1,2,...,n}中选出一个k子集,其最小值的期望,给出两个长度为
Input
第一行一整数m表示序列长度,之后输入
Output
输出A′序列
Sample Input
5
7 3 5 3 4
2 1 3 2 3
Sample Output
4 7 3 5 3
Solution
显然对于固定的k,
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=200005;
int m,a[maxn],ans[maxn];
struct node
{
int val,id;
bool operator<(const node &a)const
{
if(a.val!=val)return val>a.val;
return id<a.id;
}
}b[maxn];
int main()
{
while(~scanf("%d",&m))
{
for(int i=1;i<=m;i++)scanf("%d",&a[i]);
sort(a+1,a+m+1);
for(int i=1;i<=m;i++)scanf("%d",&b[i].val),b[i].id=i;
sort(b+1,b+m+1);
for(int i=1;i<=m;i++)ans[b[i].id]=a[i];
for(int i=1;i<=m;i++)printf("%d%c",ans[i],i==m?'\n':' ');
}
return 0;
}

本文介绍了一种通过排序实现的最大期望值匹配算法,用于解决给定两个序列如何重排一个序列使得特定函数的总和最大。该算法适用于竞赛编程及算法设计领域。
732

被折叠的 条评论
为什么被折叠?



