Codeforces_841_C Leha and Function(贪心+构造|规律)
来源:互联网 发布:最优化方法第二版答案 编辑:程序博客网 时间:2024/05/16 16:06
题目链接
题意
F(n,k): 一个1~n的集合M,从M中任意拿出k个元素,构成大小为k的子集, F(n,k)是所有子集的最小值的贡献的平均值
For example, let’s find F(4, 2). All possible 2-element subsets of {1,2,3,4} are: {1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4}. Their minimal values are 1, 1, 1, 2, 2, 3. So the average (expected) value is F(4,2)=(1+1+1+2+2+3)/6=10/6=1.66666666
现在给出两个数组,A[]和B[],让我们对A[]数组重新排序,使得** 最大(抱歉不会打数学公式,请看原题)
解决
- 理论知识待补充,这篇博客有给证明
- 观察样例,我们发现优先让A[]数组中最大的去匹配B[]数组中最小的
- 构造一个结构体,保存数字和位置
- 排序后输出
希望我的代码能被大家读懂^_^
#include<bits/stdc++.h>using namespace std;const int maxn=2e5+5;struct node{ int num,id; bool operator<(node n2)const { return num<n2.num; }}a[maxn],b[maxn];int ans[maxn];int main(){ int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i].num); a[i].id=i; } for(int i=1;i<=n;i++) { scanf("%d",&b[i].num); b[i].id=i; } sort(a+1,a+1+n); sort(b+1,b+1+n); for(int i=1;i<=n;i++) { ans[b[i].id]=a[n+1-i].num; } for(int i=1;i<=n;i++) printf("%d%c",ans[i],i==n?'\n':' ');}
阅读全文
0 0
- Codeforces_841_C Leha and Function(贪心+构造|规律)
- 【Codeforces 840 A. Leha and Function】& 构造
- C. 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 贪心
- 429c Leha and Function
- Codeforces Round #429 (Div. 2) 840A Leha and Function(贪心)
- codeforces 841C Leha and Function
- codeforces 840A Leha and Function
- Codeforces 840A 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 841D Leha and another game about graph 构造
- codeforces #429(div2)C—Leha and Function(水题)
- IO复用——epoll内核源代码剖析
- 第九篇:基本数据结构——队列的链式表示
- 阿里云安装 JDK mysql 环境搭建
- [HDU 6155] Subsequence Count
- zzuli GJJ的日常之暴富梦
- Codeforces_841_C Leha and Function(贪心+构造|规律)
- HDU 6152 Friend-Graph(拉姆齐定理+暴力)
- Qt写c++控制台中文乱码问题
- 第十篇:二叉树递归与非递归遍历(附完整源码)
- SQLite(2)
- Linux的作业管理:前台作业、后台作业
- Android开发中常用小方法
- 第十一篇:二叉树的层序遍历
- 【英语写作】2005考研英语一