题意翻译

Description

有一个长为nnn ,宽为mmm 的鱼缸,还有一个边长为rrr 的正方形渔网。你可以往鱼缸里放kkk 条鱼,问用渔网随机在浴缸里捞鱼的最大期望是多少。不懂什么是期望的自己去百度

Input

一行4个正整数代表n,m,r,kn, m, r, kn,m,r,k

Output

输出一个实数,表示最大期望

感谢@xunzhen 提供的翻译

题目描述

While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n×m n×m n×m , divided into cells of size 1×1 1×1 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 r×r r×r , designed for fishing. If the lower-left corner of the scoop-net is located at cell (x,y) (x,y) (x,y) , all fishes inside the square (x,y)...(x+r−1,y+r−1) (x,y)...(x+r-1,y+r-1) (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 k 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 k 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) (n-r+1)·(m-r+1) (n−r+1)⋅(m−r+1) possible positions, the average number of caught fishes is as high as possible.

输入输出格式

输入格式:

The only line contains four integers n,m,r,k n,m,r,k n,m,r,k ( 1<=n,m<=105 1<=n,m<=10^{5} 1<=n,m<=105 , 1<=r<=min(n,m) 1<=r<=min(n,m) 1<=r<=min(n,m) , 1<=k<=min(n⋅m,105) 1<=k<=min(n·m,10^{5}) 1<=k<=min(n⋅m,105) ).

输出格式:

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 10^{-9} 10−9 . Namely, let your answer be a a a , and the jury's answer be b b b . Your answer is considered correct, if .

输入输出样例

输入样例#1: 复制

3 3 2 3

输出样例#1: 复制

2.0000000000

输入样例#2: 复制

12 17 9 40

输出样例#2: 复制

32.8333333333

说明

In the first example you can put the fishes in cells (2,1) (2,1) (2,1) , (2,2) (2,2) (2,2) , (2,3) (2,3) (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.

很容易想到的一种思路是在被正方形覆盖次数最多的地方放?;

那么我们要做的就是给定(x,y)坐标后,求出该位置被多少个矩形所覆盖即可;

接着从该位置向四周拓展----bfs;

当然用 priority-queue维护一下即可解决;

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 300005
#define inf 0x3f3f3f3f
#define INF 9999999999
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long  ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {ll x = 0;char c = getchar();bool f = false;while (!isdigit(c)) {if (c == '-') f = true;c = getchar();}while (isdigit(c)) {x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}return f ? -x : x;
}ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; }/*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {if (!b) {x = 1; y = 0; return a;}ans = exgcd(b, a%b, x, y);ll t = x; x = y; y = t - a / b * y;return ans;
}
*/double ans = 0;
int n, m, k, r;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };struct node {int x, y;ll sum;friend bool operator <(node a, node b) {return a.sum < b.sum;}
};priority_queue<node>q;
map<pii, int>fg;bool judge(int x, int y) {if (x >= 1 && x <= n && y >= 1 && y <= m&&fg[make_pair(x,y)]==0)return true;if (fg[make_pair(x, y)])return 0;return 0;
}ll getsum(int x, int y) {ll X = min(n, x + r - 1) - max(r, x) + 1;ll Y = min(m, y + r - 1) - max(y, r) + 1;return X * Y;
}int main()
{//ios::sync_with_stdio(0);rdint(n); rdint(m); rdint(r); rdint(k);fg[make_pair((n+1)/2, (m+1)/2)] = 1;q.push(node{ (n + 1) / 2,(m + 1) / 2,getsum((n + 1) / 2,(m + 1) / 2) });while (k--) {node tmp = q.top(); q.pop();int x = tmp.x, y = tmp.y;ans += 1.0*tmp.sum / (n - r + 1) / (m - r + 1);for (int i = 0; i < 4; i++) {int nx = x + dx[i], ny = y + dy[i];if (judge(nx, ny)) {fg[make_pair(nx, ny)] = 1;q.push(node { nx, ny, getsum(nx, ny) });}}}printf("%.10lf\n", 1.0*ans);return 0;
}

转载于:https://www.cnblogs.com/zxyqzy/p/10123510.html

CF912D Fishes 期望相关推荐

  1. [NOI2005]聪聪与可可(期望dp)

    题意:给一张无向图,有一只猫和一只老鼠,猫每秒会向老鼠的方向移动两个单位,若它们的距离为一,那么只会移动一个单位,老鼠会等概率向周围移动一步或不动,求猫抓到老鼠的期望时间. Solution luog ...

  2. 洛谷P4316 绿豆蛙的归宿(期望)

    题意翻译 「Poetize3」 题目背景 随着新版百度空间的上线,Blog宠物绿豆蛙完成了它的使命,去寻找它新的归宿. 题目描述 给出一个有向无环图,起点为1终点为N,每条边都有一个长度,并且从起点出 ...

  3. LightOJ - 1038 Race to 1 Again 基础期望概率 dp

    传送门 刚刚学习期望&概率 我们设数X的期望改变次数为P[X] 如果要求X的期望,很容易想到找x的因子; 可以得到下式  ,cnt为X因子个数,ai为X的因子 可以这么理解,当因子ai为1时, ...

  4. 强化学习(五) - 时序差分学习(Temporal-Difference Learning)及其实例----Sarsa算法, Q学习, 期望Sarsa算法

    强化学习(五) - 时序差分学习(Temporal-Difference Learning)及其实例 5.1 TD预测 例5.1 回家时间的估计 5.2 TD预测方法的优势 例5.2 随机移动 5.3 ...

  5. 强化学习(一)- 强化学习介绍、Markov决策过程和贝尔曼期望方程

    强化学习(英语:Reinforcement learning,简称RL)是机器学习中的一个领域,强调如何基于环境而行动,以取得最大化的预期利益.其灵感来源于心理学中的行为主义理论,即有机体如何在环境给 ...

  6. nyoj——297(期望)

    GoroSort 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 Goro has 4 arms. Goro is very strong. You don't mess ...

  7. 《对软件工程课程的期望》

    要学习到的能力的预期:要学会个人,结对,团队的代码编辑流程,学会和别人进行交流. 对项目课程的期望:希望不是枯燥的代码详解. 对项目的愿景规划:希望团队里的每个人都能学到有用的知识. 转载于:http ...

  8. EM算法(Expectation Maximization)期望最大化算法

    原文:EM(期望最大化)算法初步认识 - 大数据和AI躺过的坑 - 博客园 https://www.cnblogs.com/zlslch/p/6965374.html 机器学习十大算法之一:EM算法( ...

  9. 2018-3-5 (论文—网络评论中结构化信息处理的应用于研究)笔记三(互信息,信息增益,期望交叉熵,基于词频的方法,CHI统计)

    传统的特征提取的方法: 1.互信息量(Mutual Information MI):评估零个随机变量相关程度(数组额上离散使用了累加,而连续是积分) 百度:互信息_百度百科 https://baike ...

最新文章

  1. AI促进药物发现:未来是多细胞研究
  2. linux c 正则表达式 简介
  3. WINCE串口WriteFile阻塞问题解决方法
  4. YFIOServer 后台IO接口使用说明
  5. js中如果无法获取某个html属性,例如自定义了一个dir属性,但获取总是为空,尝试换个词,因为可能什么关键词冲突了。...
  6. html有几个文件夹,关于webpack打包问题,怎么打包成多个文件夹,每个文件夹下有相应的html,js和css?...
  7. (10)verilog语言编写SPI发送
  8. 当Python的lambda表达式遇上变量作用域
  9. winform 图片集合
  10. 有哪些不怎么火,实际上却很厉害的软件
  11. C语言程序设计(第三版)何钦铭著 习题5-7
  12. 行业案例 | 悬镜DevSecOps智适应威胁管理解决方案获评信通院“2021云安全守卫者计划优秀案例”
  13. 【滤波器】基于时变维纳滤波器实现语音去噪含Matlab源码
  14. 创业一年半项目经验分享
  15. 获取对象上的属性(三种方法)
  16. 如何找实习工作?怎么准备?
  17. JAVA初中作品_美术作品大全初中生
  18. stroage——SAN存储与WINDOWS主机连接
  19. sap客户信贷_SAP信贷控制功能与配置详解
  20. Realtek WiFi concurrent 模式介绍

热门文章

  1. Android开发——内存优化 图片处理
  2. how-to-get-a-job-in-deep-learning
  3. 工厂方法(Factory Method)模式
  4. 实习生笔试面试题总结
  5. C# 获取几种路径的方式
  6. [JOISC2014]ストラップ
  7. ORA-12514 监听程序当前无法识别连接描述符中的服务
  8. mv命令(移动和重命名)
  9. 程序员提交代码的 emoji 指南——原来表情文字不能乱用
  10. 第18章 多线程----线程同步