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蒟蒻一起打的比赛)

最新文章

  1. iOS 10 :用 UIViewPropertyAnimator 编写动画
  2. easyUi datagrid 返回时间格式化操作
  3. fastdfs 安装配置
  4. Windows API学习---线程与内核对象的同步
  5. 从客户端中检测到有潜在危险的 Request.Form 值-解决方案
  6. php pdo(二)
  7. CXF Service Interceptor请求,响应报文之控制台输出
  8. BZOJ2324: [ZJOI2011]营救皮卡丘
  9. linux服务器性能状态查看
  10. php字符串压缩
  11. Java Maps
  12. 运维笔记--docker odoo镜像 运行异常处理
  13. MATLAB常微分方程数值解——欧拉法、改进的欧拉法与四阶龙格库塔方法
  14. MySQL 树节点递归遍历所以子节点
  15. python3笔记(二)Python语言基础
  16. POJ 1655 - Balancing Act - [DFS][树的重心]
  17. python值传递和指针传递
  18. Python学习-28.Python中的列表切片
  19. CF刷题-Codeforces Round #481-G. Petya&#39;s Exams
  20. 字幕字体滚动插件——scroxt.js

热门文章

  1. 安装破解MyEclipse2017CI
  2. nginx反向代理_负载均衡
  3. 300英雄的危机(heroes)
  4. 如何用纯 CSS 创作一个晃动的公告板
  5. Wizard&#39;s Tour CodeForces - 860D (图,构造)
  6. spring boot 发布自动生成svn版本号
  7. Git复习(七)之自定义git、忽略特殊文件、配置文件
  8. CVE-2018-0802漏洞利用
  9. 在mysql 上如何在不影响生产的情况下删除一个大表
  10. Linux和Windows双系统下Windows系统插入耳机没有声音