有趣的水题

由期望的线性性质,全局期望 = 每个格子的期望之和

由于权值一样,我们优先选概率大的点就好了

用一些数据结构来维护就好了

复杂度$O(k \log n)$

#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
namespace remoon {
#define re register
#define de double
#define le long double
#define ri register int
#define ll long long
#define sh short
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define tpr template <typename ra>
#define rep(iu, st, ed) for(ri iu = st; iu <= ed; iu ++)
#define drep(iu, ed, st) for(ri iu = ed; iu >= st; iu --)
#define gc getchar
inline int read() {
int p = , w = ; char c = gc();
while(c > '' || c < '') { if(c == '-') w = -; c = gc(); }
while(c >= '' && c <= '') p = p * + c - '', c = gc();
return p * w;
}
int wr[], rw;
#define pc(iw) putchar(iw)
tpr inline void write(ra o, char c = '\n') {
if(!o) pc('');
if(o < ) o = -o, pc('-');
while(o) wr[++ rw] = o % , o /= ;
while(rw) pc(wr[rw --] + '');
pc(c);
}
tpr inline void cmin(ra &a, ra b) { if(a > b) a = b; }
tpr inline void cmax(ra &a, ra b) { if(a < b) a = b; }
tpr inline bool ckmin(ra &a, ra b) { return (a > b) ? a = b, : ; }
tpr inline bool ckmax(ra &a, ra b) { return (a < b) ? a = b, : ; }
}
using namespace std;
using namespace remoon; namespace mod_mod {
#define mod 1000000007
inline void inc(int &a, int b) { a += b; if(a >= mod) a -= mod; }
inline void dec(int &a, int b) { a -= b; if(a < ) a += mod; }
inline int Inc(int a, int b) { return (a + b >= mod) ? a + b - mod : a + b; }
inline int Dec(int a, int b) { return (a - b < ) ? a - b + mod : a - b; }
inline int mul(int a, int b) { return 1ll * a * b % mod; }
}
using namespace mod_mod; de ans = ;
int n, m, r, k;
int nx[] = { , -, , };
int ny[] = { , , , - };
struct node {
int x, y; ll c;
friend bool operator < (node a, node b)
{ return a.c < b.c; }
};
priority_queue <node> q;
map <pii, int> vis; inline bool ck(int x, int y) {
if(x < || x > n) return ;
if(y < || y > m) return ;
if(vis[mp(x, y)]) return ;
else return ;
} inline ll solve(int x, int y) {
ll X = min(min(x, n - x + ), min(n - r + , r));
ll Y = min(min(y, m - y + ), min(m - r + , r));
return X * Y;
} int main() { n = read(); m = read();
r = read(); k = read(); vis[mp(r, r)] = ;
q.push((node){r, r, solve(r, r)}); while(k --) {
node now = q.top(); q.pop();
int x = now.x, y = now.y; ans += now.c / (de)(n - r + ) / (de)(m - r + );
rep(i, , ) {
int dx = x + nx[i], dy = y + ny[i];
if(ck(dx, dy)) {
vis[mp(dx, dy)] = ;
q.push((node){dx, dy, solve(dx, dy)});
}
}
} printf("%.9lf\n", ans);
return ;
}

CF912D Fishes 期望 + 贪心的更多相关文章

  1. CF912D Fishes 期望

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

  2. [CF912D]Fishes - 求数学期望,乱搞

    D. Fishes time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

  3. Codeforces 912 D. Fishes (贪心、bfs)

    题目链接:Fishes 题意: 有一个n×m的鱼塘,有一张r×r的渔网,现在往池塘里面放k条鱼(每个格子只能放一条鱼), 现在撒网的地方是随机的(必须在池塘内),问能捕的鱼的期望值最大是多少? 题解: ...

  4. CF912D Fishes

    题目链接:http://codeforces.com/contest/912/problem/D 题目大意: 在一个\(n \times m\)的网格中放鱼(每个网格只能放一条鱼),用一个\(r \t ...

  5. bzoj 3143 [Hnoi2013]游走(贪心,高斯消元,期望方程)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3143 [题意] 给定一个无向图,从1走到n,走过一条边得到的分数为边的标号,问一个边的 ...

  6. CodeForces 912d fishes(优先队列+期望)

    While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of ...

  7. Luogu3232 HNOI2013 游走 高斯消元、期望、贪心

    传送门 这种无向图上从一个点乱走到另一个点的期望题目好几道与高斯消元有关 首先一个显然的贪心:期望经过次数越多,分配到的权值就要越小. 设$du_i$表示$i$的度,$f_i$表示点$i$的期望经过次 ...

  8. BZOJ 3143 游走(贪心+期望+高斯消元)

    一个无向连通图,顶点从1编号到N,边从1编号到M. 小Z在该图上进行随机游走,初始时小Z在1号顶点,每一步小Z以相等的概率随机选 择当前顶点的某条边,沿着这条边走到下一个顶点,获得等于这条边的编号的分 ...

  9. CF605E Intergalaxy Trips 贪心 概率期望

    (当时写这篇题解的时候,,,不知道为什么,,,写的非常冗杂,,,不想改了...) 题意:一张有n个点的图,其中每天第i个点到第j个点的边都有$P_{i, j}$的概率开放,每天可以选择走一步或者留在原 ...

随机推荐

  1. Linux操作系统介绍

    1Linux操作系统介绍 1.1linux系统的应用 服务器系统:Web应用服务器.数据库服务器.接口服务器.DNS.FTP等等: 嵌入式系统:路由器.防火墙.手机.PDA.IP 分享器.交换器.家电 ...

  2. [Openwrt扩展中篇]添加Aria2和webui

    上一篇说了我构建了简单的网络硬盘,这一篇说的是我构造的aria2和webui,大概是这样我觉得有了网络硬盘,那么我是不是可以远程下载呢,翻阅了网上资料发现迅雷的Xware貌似不更新了,然后我发现了ar ...

  3. D. Sum in the tree(树形+贪心)

    题目链接;http://codeforces.com/contest/1099/problem/D 题目大意:给出一棵树,每个节点到根节点的路径上经过的所有点的权值之和,其深度为偶数的节点的信息全部擦 ...

  4. 延迟注入工具(python)

    延迟注入工具(python) #!/usr/bin/env python # -*- coding: utf-8 -*- # 延迟注入工具 import urllib2 import time imp ...

  5. Servlet笔记6--Servlet程序改进

    第一步改进,GenericServlet: 我们目前所有放入Servlet类直接实现了javax.servlet.Servlet接口,但是这个接口中有很多方法是目前不需要的,我们可能只需要编写serv ...

  6. Linux禁止ping的俩种方法【转】

    Linux禁止ping以及开启ping的方法   Linux默认是允许Ping响应的,系统是否允许Ping由2个因素决定的:A.内核参数,B.防火墙,需要2个因素同时允许才能允许Ping,2个因素有任 ...

  7. clog,cout,cerr 输出机制

    clog:控制输出,使其输出到一个缓冲区,这个缓冲区关联着定义在 <cstdio> 的 stderr. cerr:强制输出刷新,没有缓冲区. cout:控制输出,使其输出到一个缓冲区,这个 ...

  8. 八、springboot整合redis

    整合Redis 一. 注解方式实现添加缓存 1.在pom.xml加入依赖 <!-- 配置使用redis启动器 --> <dependency> <groupId>o ...

  9. centos7 yum搭建lamp环境

    =============================================== 2018/1/14_第1次修改                       ccb_warlock == ...

  10. Sql Server2005 Transact-SQL 新兵器学习总结之-排名函数

    Transact-SQL提供了4个排名函数: rand() , dense_rand() , row_number() , ntile() 下面是对这4个函数的解释:rank() 返回结果集的分区内每 ...