time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output

While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).

The gift bundle also includes a square scoop of size r × r, designed for fishing. If the lower-left corner of the scoop-net is located at cell (x, y), all fishes inside the square (x, y)...(x + r - 1, y + r - 1) get caught. Note that the scoop-net should lie completely inside the pond when used.

Unfortunately, Sasha is not that skilled in fishing and hence throws the scoop randomly. In order to not frustrate Sasha, Misha decided to release k fishes into the empty pond in such a way that the expected value of the number of caught fishes is as high as possible. Help Misha! In other words, put k fishes in the pond into distinct cells in such a way that when the scoop-net is placed into a random position among (n - r + 1)·(m - r + 1) possible positions, the average number of caught fishes is as high as possible.

Input

The only line contains four integers n, m, r, k (1 ≤ n, m ≤ 105, 1 ≤ r ≤ min(n, m), 1 ≤ k ≤ min(n·m, 105)).

Output

Print a single number — the maximum possible expected number of caught fishes.

You answer is considered correct, is its absolute or relative error does not exceed 10 - 9. Namely, let your answer be a, and the jury's answer be b. Your answer is considered correct, if .

Examples
input
3 3 2 3
output
2.0000000000
input
12 17 9 40
output
32.8333333333
Note

In the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value.

题目大意

给一个n*m的网格,让你在里面放k条鱼,用r*r的网覆盖(共(n - r + 1)·(m - r + 1)种方法),求覆盖到鱼的数量的期望值,(保留10位小数?)


题解

放k条鱼,不如考虑每个格子放一条鱼带来的效益

写了个暴力程序,跑出每个格子的效益:

 daklqw@daklqw:~/workspace/code$ ./test233

 daklqw@daklqw:~/workspace/code$ ./test233

可以很方便地发现,从中间到周围,效益是不断减少的

所以我们从中间开始贪心这k条鱼,而由于这个性质,我们可以使用BFS+优先队列,每次选出一个效益最大的往四边扩展

注意到k不大,而n*m非常大,如果开二维数组会MLE,所以考虑使用set

下面献上代码:

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;
int n,m,r,k;
const int ways[][]={{,},{,},{-,},{,-}};
double ans,tot;
struct element{
int x,y;long long val;
inline bool operator<(const element & b)const{
return val<b.val;
}
};
inline long long getv(int x,int y){
int t1=max(x-r+,),t2=max(y-r+,),
t3=min(x+r-,n)-r+,t4=min(y+r-,m)-r+;//一时想不出更好的
if(t3<t1|t4<t2)return -;//防BOOM
return 1LL*(t3-t1+)*(t4-t2+);
}
priority_queue<element>q;
set<pair<int,int> >s;
int main(){
scanf("%d%d%d%d",&n,&m,&r,&k);
if(n>m)swap(n,m);//貌似没什么用
q.push((element){n+>>,m+>>,getv(n+>>,m+>>)});
s.insert(make_pair(n+>>,m+>>));
for(register int i=;i<=k;++i){//找K个
element t=q.top();q.pop();
tot+=t.val;
for(register int j=;j<;++j){//BFS
int tx=t.x+ways[j][],
ty=t.y+ways[j][];
if(tx<||ty<||tx>n||ty>m)continue;
if(s.find(make_pair(tx,ty))!=s.end())continue;
q.push((element){tx,ty,getv(tx,ty)});
s.insert(make_pair(tx,ty));
}
}
printf("%.10lf\n",tot/double(n-r+)/double(m-r+));//输出期望值
return ;
}

124ms,貌似不慢,并没有时间参加这场,所以开了模拟比赛(我们这些没rating的div2蒟蒻一起打的比赛)

[CF912D]Fishes - 求数学期望,乱搞的更多相关文章

  1. HDU 1099 Lottery (求数学期望)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1099 Lottery Time Limit: 2000/1000 MS (Java/Others)   ...

  2. [BZOJ3751][NOIP2014]解方程(数学相关+乱搞)

    题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, m ] 内的整数解(n 和m 均为正整数) 输入输出格式 输入格式: 输入文件名为equation .i ...

  3. BZOJ2134: 单选错位(期望乱搞)

    Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 1101  Solved: 851[Submit][Status][Discuss] Descripti ...

  4. uva 10828 高斯消元求数学期望

    Back to Kernighan-RitchieInput: Standard Input Output: Standard Output You must have heard the name ...

  5. [2013山东ACM]省赛 The number of steps (可能DP,数学期望)

    The number of steps nid=24#time" style="padding-bottom:0px; margin:0px; padding-left:0px; ...

  6. 直径上的乱搞 bzoj1999求树直径上的结点+单调队列,bzoj1912负权树求直径+求直径边

    直径上的乱搞一般要求出这条直径上的点集或者边集 bzoj1999:对直径上的点集进行操作 /* 给出一颗树,在树的直径上截取长度不超过s的路径 定义点u到s的距离为u到s的最短路径长度 定义s的偏心距 ...

  7. Luogu P1134 阶乘问题 【数学/乱搞】 By cellur925

    输入输出格式 输入格式: 仅一行包含一个正整数 NN . 输出格式: 一个整数,表示最右边的非零位的值. 输入输出样例 输入样例#1: 12 输出样例#1: 6 说明 USACO Training S ...

  8. BZOJ-1800 飞行棋 数学+乱搞

    这道题感觉就是乱搞,O(n^4)都毫无问题 1800: [Ahoi2009]fly 飞行棋 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 1172 So ...

  9. “盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛题解&&源码【A,水,B,水,C,水,D,快速幂,E,优先队列,F,暴力,G,贪心+排序,H,STL乱搞,I,尼姆博弈,J,差分dp,K,二分+排序,L,矩阵快速幂,M,线段树区间更新+Lazy思想,N,超级快速幂+扩展欧里几德,O,BFS】

    黑白图像直方图 发布时间: 2017年7月9日 18:30   最后更新: 2017年7月10日 21:08   时间限制: 1000ms   内存限制: 128M 描述 在一个矩形的灰度图像上,每个 ...

随机推荐

  1. Oracle网络相关概念与常用配置文件

    监听器(Listener) 监听器是Oracle基于服务端的一种网络服务,主要用于监听客户端向数据库服务器提出的链接请求. 本地服务名(Tnsname) Oracle客户端与服务器端的链接是通过客户端 ...

  2. SpringBoot项目打成Jar包时运行

    使用java -jar ***.jar执行jar包的时候,会找jar包中的main()方法. 对于SpringBoot项目的Jar包,在META-INF目录下的MANIFEST.MF文件中,Main- ...

  3. Test:河北金力集团企业网集成

    三.网站建设部分(40分) 河北金力集团公文流转系统 1.项目需求: 河北金力集团是我省机械加工的龙头企业,主要从事矿山机械制造及各种机械零部件加工.企业有3个厂区,主厂区位于省高新技术开发区,3个分 ...

  4. FFmpeg4.0笔记:本地媒体文件解码、帧格式转换、重采样、编码、封装、转封装、avio、硬解码等例子

    Github https://github.com/gongluck/FFmpeg4.0-study/blob/master/official%20example/my_example.cpp #in ...

  5. Java中创建的对象多了,必然影响内存和性能

    1, Java中创建的对象多了,必然影响内存和性能,所以对象的创建越少越好,最后还要记得销毁.

  6. 使用Python基于VGG/CTPN/CRNN的自然场景文字方向检测/区域检测/不定长OCR识别

    GitHub:https://github.com/pengcao/chinese_ocr https://github.com/xiaofengShi/CHINESE-OCR |-angle 基于V ...

  7. 9.用ExecuteSqlCommand执行存储过程

    比如你有一个存储过程 IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CreateAutho ...

  8. 02 Linux常用基本命令(二)

    1.Linux的文件系统格式 1.以 / 为根目录,成树状结构分布 2.查看根目录下有什么 ls / 3./下有超级用户root的家目录(root),还有普通用户的家目录(/home) 4.常用文件夹 ...

  9. TensorFlow入门——安装

    由于实验室新配了电脑,旧的电脑就淘汰下来不用,闲来无事,就讲旧的电脑作为个人的工作站来使用. 由于在旧电脑上安装的是Ubuntu 16.04 64bit系统,系统自带的是Python 2.7,版本选择 ...

  10. Docker搭建Gitlab服务器

    1.使用docker搜索gitlab镜像 docker search gitlab 2.下载镜像: docker pull docker.io/gitlab/gitlab-ce 3.查看docker镜 ...