cf912D
题意简述:往n*m的网格中放k条鱼,一个网格最多放一条鱼,然后用一个r*r的网随机去捞鱼,问怎么怎么放鱼能使得捞鱼的期望最大,输出这个期望
题解:肯定优先往中间放,这里k不大,因此有别的简单方法,否则推公式各种情况烦死人,我们对于每一行来说将中间的数加进去,然后用set来维护k次就好了
#include<bits/stdc++.h>
#define forn(i, n) for (int i = 0 ; i < int(n) ; i++)
#define fore(i, s, t) for (int i = s ; i < (int)t ; i++)
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf(x) printf("%d\n",x)
#define each(x) for(auto it:x) cout<<it<<endl;
#define pii pair<int,int>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int maxm=2e5+5;
const int inf=1e9;
int n,m,r,k;
struct cell{
int x,y,d;
ll val;
cell(int x,int y,int d):x(x),y(y),d(d){
val=(min(m+1,y+r)-max(y,r))*1ll*(min(n+1,x+r)-max(x,r));
}
bool operator<(const cell& rhs)const {
return val>rhs.val;
}
};
multiset<cell> ms;
double calc(){
for (int i = 1; i <= n; i++) {
int j = m / 2;
ms.insert({ i, j, 0 });
ms.insert({ i, j + 1, 1 });
}
ll total = 0;
for(int i=0;i<k;i++){
auto it = *ms.begin();
total += it.val;
ms.erase(ms.begin());
if (it.d == 1 && it.y < m)
ms.insert({ it.x, it.y + 1, 1 });
else if (it.d == 0 && it.y > 1)
ms.insert({ it.x, it.y - 1, 0 });
}
return (double)total / ((n - r + 1) * 1LL * (m - r + 1));
}
int main(){
cin>>n>>m>>r>>k;
if(n>m) swap(n,m);
if(m==1) {
printf("%.10f\n",1.0);
}
else {
printf("%.10f\n",calc());
}
}
cf912D的更多相关文章
- CF912D Fishes 期望 + 贪心
有趣的水题 由期望的线性性质,全局期望 = 每个格子的期望之和 由于权值一样,我们优先选概率大的点就好了 用一些数据结构来维护就好了 复杂度$O(k \log n)$ #include <set ...
- CF912D Fishes 期望
题意翻译 Description 有一个长为nnn ,宽为mmm 的鱼缸,还有一个边长为rrr 的正方形渔网.你可以往鱼缸里放kkk 条鱼,问用渔网随机在浴缸里捞鱼的最大期望是多少.不懂什么是期望的自 ...
- [CF912D]Fishes - 求数学期望,乱搞
D. Fishes time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
- CF912D Fishes
题目链接:http://codeforces.com/contest/912/problem/D 题目大意: 在一个\(n \times m\)的网格中放鱼(每个网格只能放一条鱼),用一个\(r \t ...
- cf期望概率专题
cf1009E:求到第i段期望和的比较困难,但是单独求每段的期望是比较容易的,所以单独对每段求和,然后累计总和 E[i]=1/2*a1+1/4*a2+...+1/2^(i-1)*ai-1+1/2^(i ...
随机推荐
- Shell环境变量文件
/etc/profile 系统级的初始化环境变量文件,由登录Shell调用执行 /etc/profile.d 当/etc/profile运行时,会调用该目录下的一些脚本 /etc/bashrc 每个交 ...
- MySQL 清理缓存—flush tablesFlush tables的影响
摘自:http://blog.chinaunix.net/uid-31401119-id-5781305.html 1 Flush tables简介 官方手册中关于Flush tables的介绍, ...
- CUDA学习(三)之使用GPU进行两个数相加
在CPU上定义两个数并赋值,然后使用GPU核函数将两个数相加并返回到CPU,在CPU上显示 #include "cuda_runtime.h" #include "dev ...
- 倒转数组 Leetcode189
倒转数组 Leetcode189 记录调整数组顺序而不需要另加内存的一种方法: 题目 189. 旋转数组 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数. 示例 1: 输入: [ ...
- MybatisDao
一.mybatisDao的编写(原始方式,不用) 1.接口编写 public interface UserDao { public void save(User user); public User ...
- 自己封装的一个Ajax小框架
在经历了Jsp实训的惨痛教训后,特意花了点时间学习Ajax,学完后自我感觉良好,于是写了如下一个小框架: /** * frameAjax * * 参数: * paramsObj: Json * req ...
- C2440 “初始化”: 无法从“std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>”转换为“std::_Vector_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>”
错误原因vs已经提醒的很清楚了:无法将const_iterator转换为iterator 我的出错代码是这样的 思考了很久,最后发现原来是因为将函数定义为const的缘故. 总结:当将函数定义为con ...
- RFC笔记—Neighbor Discovery for IP version 6 (IPv6)
Router Solicitation Message Source Address An IP address assigned to the sending interface, or the u ...
- docker集合
docker集合 docker(1):容器技术简介 docker(2):docker的“前身”—lxc docker(3):docker简介 docker(4):docker的安装(centos7)和 ...
- 《自拍教程19》ffmpeg_音视频图像转码工具
ffmpeg命令介绍 ffmpeg.exe(linux/imac一般不带后缀,ffmpeg), 是一款音视频编解码的命令行工具软件, 常用于多媒体测试的文件制作与转码. 我们常用的:格式工厂,Medi ...