• 429c Leha and Function


    题目

    20170819150311038362084.png

    解题报告

    F(n, k)是在集合{1, 2, 3, ..., n}中所有的具有k个元素的子集中分别取最小值,相加后的期望。
    例如:要求F(4, 2) ,根据定义有{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4},则F(4, 2)=(1+1+1+2+2+3)/6=1.6666666666666...

    对于F(n, k),我们有这么一个结论,
    $$ F(n, k) > F(m, k), n > m $$
    $$F(n, k) > F(n, q), k < q $$

    因此,原问题变为将A按照由大到小排序后,求B数组每个元素在排序后的编号,在此位置输出排序后的Ai

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    #define ms(s) memset(s, 0, sizeof(s))
    #define REP(i, k, n) for (int i = k; i < n; i++)
    #define REPP(i, k, n) for (int i = k; i <= n; i++)
    const int inf = 0x3f3f3f3f;
    #define LOCAL
    int a[200005], h[200005];
    
    pair<int, int> b[200005];
    bool cmp(int a, int b)
    {
    	return a > b;
    }
    
    bool cmp1(pair<int, int> a, pair<int, int> b)
    {
    	return a.first < b.first;
    }
    
    int main(int argc, char * argv[]) 
    {
    	#ifdef LOCAL
    	freopen("/Users/huangjiaming/Documents/Algorithm/oj/data.in", "r", stdin);
    	//freopen("/Users/huangjiaming/Documents/Algorithm/oj/data.out", "w", stdout);
    	#endif
    
    	int n;
    
    	while (~scanf("%d", &n))
    	{
    
    		REPP(i, 1, n)
    		scanf("%d", a+i);
    		REPP(i, 1, n)
    		{
    			scanf("%d", &b[i].first);
    			b[i].second = i;
    		}
    		sort(a+1, a+n+1, cmp);
    		sort(b+1, b+n+1, cmp1);		
    		REPP(i, 1, n)
    		h[b[i].second] = i;
    		REPP(i, 1, n)
    		printf("%d ", a[h[i]]);
    		
    		printf("
    ");
    	}
    
        return 0;
    }
    
    地址 http://sshpark.com.cn/
  • 相关阅读:
    Jupyter notbook快捷键
    tensorboard 的使用
    numpy——数组存取
    numpy——使用函数创建(2)
    numpy——使用array创建(1)
    python列表与元组
    python 格式化输出
    全排列递归算法
    【机器学习】ex1-线性回归
    【Web安全】三、SQL盲注
  • 原文地址:https://www.cnblogs.com/huangjiaming/p/7395921.html
Copyright © 2020-2023  润新知