429c Leha and Function
来源:互联网 发布:太平天国知乎 编辑:程序博客网 时间:2024/06/04 19:20
题目
解题报告
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 LOCALint 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("\n"); } return 0;}
阅读全文
0 0
- 429c Leha and Function
- C. Leha and Function
- Codeforces-429-2-C Leha and Function
- C. Leha and Function(Round #429 (Div. 2)
- codeforces Div.2 #429 B.Godsend C. Leha and Function
- codeforces 841C Leha and Function
- Leha and Function CodeForces
- cf840A Leha and function
- A. Leha and Function
- Leha and Function CodeForces
- CodeForces 841C (C) Leha and Function 贪心
- codeforces #429(div2)C—Leha and Function(水题)
- Codeforces Round #429 (Div. 2):C、&840A、 Leha and Function
- 【Codeforces 840 A. Leha and Function】& 构造
- codeforces 840A Leha and Function
- Codeforces_841_C Leha and Function(贪心+构造|规律)
- Codeforces 840A Leha and Function
- Codeforces Round #429 (Div. 2) 840A Leha and Function(贪心)
- 内存管理工具Memory Analyzer的使用
- 在cygwin下安装CRF++
- C++ Template基本术语(6)---《C++ Templates》
- jQuery和css3实现多功能效果
- Linux系统的邮件服务
- 429c Leha and Function
- ccf认证集合竞价
- 大学生活随笔
- 我本可以忍受黑暗,如果我不曾见过太阳。
- JAVA 开发人工智能
- 51nod 1203 JZPLCM 莫队算法
- 使用LinkedList实现安全队列
- java httpclient POST和GET请求 发送JSON
- 学习博客大集锦