429c Leha and Function
题目

解题报告
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("\n");
}
return 0;
}
429c Leha and Function的更多相关文章
- Codeforces Round #429 (Div. 2/Div. 1) [ A/_. Generous Kefa ] [ B/_. Godsend ] [ C/A. Leha and Function ] [ D/B. Leha and another game about graph ] [ E/C. On the Bench ] [ _/D. Destiny ]
PROBLEM A/_ - Generous Kefa 题 OvO http://codeforces.com/contest/841/problem/A cf 841a 解 只要不存在某个字母,它的 ...
- CodeForces 840A - Leha and Function | Codeforces Round #429 (Div. 1)
/* CodeForces 840A - Leha and Function [ 贪心 ] | Codeforces Round #429 (Div. 1) A越大,B越小,越好 */ #includ ...
- 【CodeForces】841C. Leha and Function(Codeforces Round #429 (Div. 2))
[题意]定义函数F(n,k)为1~n的集合中选择k个数字,其中最小数字的期望. 给定两个数字集A,B,A中任意数字>=B中任意数字,要求重组A使得对于i=1~n,sigma(F(Ai,Bi))最 ...
- [Codeforces 841C]Leha and Function
题目大意:定义函数F(n,k)为[1,2,3,..n]中k个元素的子集中最小元素的数学期望.现在给你两个长度相等的数列A,B(A中元素严格大于B中元素),现在要你重新排列A,使得$\sum\limit ...
- 【Codeforces Round #429 (Div. 2) C】Leha and Function
[Link]:http://codeforces.com/contest/841/problem/C [Description] [Solution] 看到最大的和最小的对应,第二大的和第二小的对应. ...
- 朱世杰恒等式的应用-以CF841C为例
题目大意 Codeforces 841C Leha and Function. 令\(F(n,k)\)为在集合\(\{x|x \in [1,n]\}\)中选择一个大小为k的子集,最小元素的期望值. 给 ...
- Codeforces Round #429 (Div. 2) 补题
A. Generous Kefa 题意:n个气球分给k个人,问每个人能否拿到的气球都不一样 解法:显然当某种气球的个数大于K的话,就GG了. #include <bits/stdc++.h> ...
- Codeforces Round #429 (Div. 2)
A. Generous Kefa One day Kefa found n baloons. For convenience, we denote color of i-th baloon as ...
- codeforces Round#429 (Div2)
2017-08-20 10:00:37 writer:pprp 用头文件#include <bits/stdc++.h>很方便 A. Generous Kefa codeforces 84 ...
随机推荐
- MySQL workbench8.0 CE基本用法(创建数据库、创建表、创建用户、设置用户权限、创建SQL语句脚本)
原文地址:https://blog.csdn.net/zgcr654321/article/details/82156277 安装完成MySQL后,打开MySQL workbench8.0. 可以看到 ...
- 走进矩阵树定理--「CodePlus 2017 12 月赛」白金元首与独舞
n,m<=200,n*m的方阵,有ULRD表示在这个格子时下一步要走到哪里,有一些待决策的格子用.表示,可以填ULRD任意一个,问有多少种填法使得从每个格子出发都能走出这个方阵,答案取模.保证未 ...
- ****使用ftp软件上传下载php文件时换行符丢失bug
在使用ftp软件上传下载php源文件时,我们偶尔会发现在本地windows下notepad++编辑器写好的php文件,在使用ftp上传到linux服务器后,php文件的换行符全部丢失了,导致php文件 ...
- Minimum Depth of Binary Tree(二叉树DFS)
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- python爬虫实现原理
前言 简单来说互联网是由一个个站点和网络设备组成的大网,我们通过浏览器访问站点,站点把HTML.JS.CSS代码返回给浏览器,这些代码经过浏览器解析.渲染,将丰富多彩的网页呈现我们眼前: 一.爬虫是什 ...
- Android: Mac无法找到Android SDK问题
通过brew cask install android-sdk后,Intellij Idea中设置Android SDK路径失败,解决方法如下: /usr/local/Caskroom/android ...
- Windows系统下JAVA开发环境搭建
首先我们需要下载JDK(JAVA Development Kit),JDK是整个java开发的核心,它包含了JAVA的运行环境,JAVA工具和JAVA基础的类库. 下载地址:http://www.or ...
- vi,vim的基本使用方法
"i”插入 "/" 查找 "wq"保存退出 "q!"不保存退出
- Spring_2_Spring中lazy-init和scope属性
1)springTest类: public class springTest { @Test public void instanceSpring() { AbstractApplicationCon ...
- Sharpdevelop如何在项目中添加类文件
点击文件-新建-文件,然后再工程内创建文件 或者工程-添加-新建项