Codeforces 840A Leha and Function
来源:互联网 发布:mina 接收不到数据 编辑:程序博客网 时间:2024/05/16 04:22
题意:给定两个数列A,B,A的最小的数大于等于B的最大的数。然后有个函数,F(n,k),就是求从[1,2,3...n]中取k个元素形成一个子集,然后求所有k个元素组成的子集中最小的元素的数学期望。任务是MAX 求和F(A[i], B[i])
题解:本来以为是要求递推式,真去求出数学期望,然后再取最大值对应A的排列。后来发现一个规律,就是给定一个n ,k越大, F(n,k)是单调递减的(大概是因为,越到后面,越来越多的子集的最小值变成了整个数列的最小值或者次小值)。所以只要将A最大的对应B最小的即可。
代码如下:
#include <iostream>#include <algorithm>using namespace std;#define N 200005int a[N],ans[N];struct node{int num;int i;}b[N]; int cmp(node a, node b){return a.num > b.num;}int main(){int n;cin >> n;for(int i = 0;i < n; ++i)cin >> a[i];for(int i = 0;i < n; ++i){b[i].i = i;cin >> b[i].num;}sort(a,a+n);sort(b,b+n,cmp);for(int i = 0;i < n; ++i)ans[b[i].i] = a[i];for(int i = 0;i < n; ++i)cout << ans[i] << " ";return 0;}
阅读全文
2 0
- 【Codeforces 840 A. Leha and Function】& 构造
- codeforces 840A Leha and Function
- Codeforces 840A Leha and Function
- Leha and Function CodeForces
- Leha and Function CodeForces
- A. Leha and Function
- Codeforces Round #429 (Div. 2) 840A Leha and Function(贪心)
- Codeforces Round #429 (Div. 2):C、&840A、 Leha and Function
- codeforces 841C Leha and Function
- Codeforces-429-2-C Leha and Function
- C. Leha and Function
- cf840A Leha and function
- codeforces Div.2 #429 B.Godsend C. Leha and Function
- CodeForces 841C (C) Leha and Function 贪心
- 429c Leha and Function
- Codeforces 840B:Leha and another game about graph
- codeforces #429(div2)C—Leha and Function(水题)
- Codeforces_841_C Leha and Function(贪心+构造|规律)
- 图像分析:二值图像连通域标记
- nginx-tomcat
- hdu1723Distribute Message(初学动态规划)
- java中父类的静态代码块,非静态代码块,构造方法,子类的静态代码块,构造方法等先后执行顺序
- bufferedReader 读取文件第一行第一个字符丢失问题
- Codeforces 840A Leha and Function
- viewpager自动轮播 加小圆点
- leetcode[Minimum Index Sum of Two Lists]//待整理多种解法
- IPC机制(一)
- 328. Odd Even Linked List
- BZOJ 3930 [CQOI2015]选数 & 51nod 1244 莫比乌斯函数之和 & BZOJ 2301
- 根轨迹图、Bode图、Nyquist图的Matlab仿真
- 关于JavaScript调试的十来个小技巧
- BZOJ[4690]Never Wait for Weights 加权并查集