#贪心#CF840A Leha and Function
题目
设 \(f(n,k)\) 表示 区间 \([1,n]\) 选出 \(k\) 个元素的集合的期望最小值,
现在需要重排 \(a\) 数组,使得 \(\sum_{i=1}^mf(a_i,b_i)\) 最大
分析
\]
这个式子可以推出来答案是 \(\frac{n+1}{k+1}\)
还可以通过模型转换,
期望最小值也就是 \([0,n+1]\) 的线段分为 \(k+1\) 个部分,
最左边线段的期望长度也就是 \(\frac{n+1}{k+1}\)
不管怎样,拿 \(a\) 中 大的与 \(b\) 中小的匹配即可
代码
#include <cstdio>
#include <cctype>
#include <algorithm>
#define rr register
using namespace std;
const int N=200011;
int a[N],b[N],rk[N],Rk[N],ans[N],n;
inline signed iut(){
rr int ans=0; rr char c=getchar();
while (!isdigit(c)) c=getchar();
while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
return ans;
}
inline void print(int ans){
if (ans>9) print(ans/10);
putchar(ans%10+48);
}
bool cmp0(int x,int y){return a[x]>a[y];}
bool cmp1(int x,int y){return b[x]<b[y];}
signed main(){
n=iut();
for (rr int i=1;i<=n;++i) a[i]=iut(),rk[i]=i;
for (rr int i=1;i<=n;++i) b[i]=iut(),Rk[i]=i;
sort(rk+1,rk+1+n,cmp0),sort(Rk+1,Rk+1+n,cmp1);
for (rr int i=1;i<=n;++i) ans[Rk[i]]=a[rk[i]];
for (rr int i=1;i<=n;++i) print(ans[i]),putchar(i==n?10:32);
return 0;
}
#贪心#CF840A Leha and Function的更多相关文章
- CodeForces 840A - Leha and Function | Codeforces Round #429 (Div. 1)
/* CodeForces 840A - Leha and Function [ 贪心 ] | Codeforces Round #429 (Div. 1) A越大,B越小,越好 */ #includ ...
- 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 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] 看到最大的和最小的对应,第二大的和第二小的对应. ...
- 【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))最 ...
- 429c Leha and Function
题目 解题报告 F(n, k)是在集合{1, 2, 3, ..., n}中所有的具有k个元素的子集中分别取最小值,相加后的期望. 例如:要求F(4, 2),根据定义有{1, 2}, {1, 3}, { ...
- 朱世杰恒等式的应用-以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
Table of Contents A. Generous KefaB. GodsendC. Leha and Function A. Generous Kefa One day Kefa found ...
- Codeforces Round #429 (Div. 2)
A. Generous Kefa One day Kefa found n baloons. For convenience, we denote color of i-th baloon as ...
随机推荐
- kafka学习笔记03-消息生产者producer
kafka学习笔记03-消息生产者producer 发送消息整体流程示意图 消息发送的流程示意图: (From:High-level overview of Kafka producer compon ...
- MyBaits查询MySQL日期类型结果相差8个小时
问题描述 在Java项目中使用MyBatis作为ORM框架,但是查询出的MySQL日期类型字段值总是比数据库表里的值多8个小时. 具体说明: MySQL数据库表字段类型为timestamp,映射的Ja ...
- 临时修改session日期格式冲突问题
输入的格式要看你安装的ORACLE字符集的类型, 比如: US7ASCII, date格式的类型就是: '01-Jan-01' alter session set NLS_DATE_LANGUAGE ...
- python字符串模板文本处理之Template
from string import Template s = Template('$who 在 $do') ts = s.substitute(who="张三", do=&quo ...
- Kotlin 协程三 —— 数据流 Flow
目录 一.Flow 的基本使用 1.1 Sequence 与 Flow 1.2 Flow 的简单使用 1.3 创建常规 Flow 的常用方式: 1.4 Flow 是冷流(惰性的) 1.5 Flow 的 ...
- 【防忘笔记】一个例子理解Pytorch中一维卷积nn.Conv1d
一维卷积层的各项参数如下 torch.nn.Conv1d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1 ...
- 【Azure 应用服务】Azure App Service多实例中,出现某一个实例CPU居高不下的情况,如何重启单个实例呢?
问题描述 在使用App Service服务中,当多实例中,其中一个实例出现高CPU,高Memory的情况,为了尽可能少的影响正在运行的应用,需要单独重启某一个实例的情况下,如何手动操作呢? 问题解答 ...
- 【Azure 应用服务】Function App中的函数(Functions)删除问题
问题描述 Function App 中的函数如何删除问题 问题分析 1)在Function App的门户上,点击"Delete"进行删除 2) 进入Function App的高级管 ...
- C++ STL 容器 forward_list类型
C++ STL 容器 forward_list类型 介绍 std::forward_list 是 C++ 标准模板库 (STL) 中的一个单向链表容器.与 std::list 不同,std::forw ...
- C++ //类模板分文件编写问题及解决 //第一中解决方式 直接包含源文件 //第二种解决方法 将.h 和 cpp的内容写到一起,将后缀改为.hpp文件
1 //第一种方式被注释 2 //未被注释是第二种方式 3 //类模板分文件编写问题及解决 4 5 6 #include <iostream> 7 #include <string& ...