CF912D Fishes 期望 + 贪心

有趣的水题
由期望的线性性质,全局期望 = 每个格子的期望之和
由于权值一样,我们优先选概率大的点就好了
用一些数据结构来维护就好了
复杂度$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 期望 + 贪心的更多相关文章
- 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 ...
- Codeforces 912 D. Fishes (贪心、bfs)
题目链接:Fishes 题意: 有一个n×m的鱼塘,有一张r×r的渔网,现在往池塘里面放k条鱼(每个格子只能放一条鱼), 现在撒网的地方是随机的(必须在池塘内),问能捕的鱼的期望值最大是多少? 题解: ...
- CF912D Fishes
题目链接:http://codeforces.com/contest/912/problem/D 题目大意: 在一个\(n \times m\)的网格中放鱼(每个网格只能放一条鱼),用一个\(r \t ...
- bzoj 3143 [Hnoi2013]游走(贪心,高斯消元,期望方程)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3143 [题意] 给定一个无向图,从1走到n,走过一条边得到的分数为边的标号,问一个边的 ...
- CodeForces 912d fishes(优先队列+期望)
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of ...
- Luogu3232 HNOI2013 游走 高斯消元、期望、贪心
传送门 这种无向图上从一个点乱走到另一个点的期望题目好几道与高斯消元有关 首先一个显然的贪心:期望经过次数越多,分配到的权值就要越小. 设$du_i$表示$i$的度,$f_i$表示点$i$的期望经过次 ...
- BZOJ 3143 游走(贪心+期望+高斯消元)
一个无向连通图,顶点从1编号到N,边从1编号到M. 小Z在该图上进行随机游走,初始时小Z在1号顶点,每一步小Z以相等的概率随机选 择当前顶点的某条边,沿着这条边走到下一个顶点,获得等于这条边的编号的分 ...
- CF605E Intergalaxy Trips 贪心 概率期望
(当时写这篇题解的时候,,,不知道为什么,,,写的非常冗杂,,,不想改了...) 题意:一张有n个点的图,其中每天第i个点到第j个点的边都有$P_{i, j}$的概率开放,每天可以选择走一步或者留在原 ...
随机推荐
- Python Webdriver 重新使用已经打开的浏览器实例
因为Webdriver每次实例化都会新开一个全新的浏览器会话,在有些情况下需要复用之前打开未关闭的会话.比如爬虫,希望结束脚本时,让浏览器处于空闲状态.当脚本重新运行时,它将继续使用这个会话工作.还就 ...
- scp加端口号
scp -P 21110 root@192.168.0.1:/home/abc.txt root@192.168.0.2:/root 注意: 参数-P 的位置一定要紧跟在scp命令后面 参数-P 指的 ...
- 79.ZYNQ内部私有定时器中断
上篇文章实现了了PS接受来自PL的中断,本片文章将在ZYNQ的纯PS里实现私有定时器中断.每个一秒中断一次,在中断函数里计数加1,通过串口打印输出. *本文所使用的开发板是Miz702(兼容zedbo ...
- MongoDB安全:创建角色(User-Defined Roles)
MongoDB已经定义了一些内建角色,同时还提供了用户自定义角色的功能,以满足用户千差万别的需求. 官文User-Defined Roles中对其有简略介绍,但要熟悉怎么创建角色,还需要了解下面的这些 ...
- Java线程:新特征-有返回值的线程《转》
原始文章 在Java5之前,线程是没有返回值的,常常为了“有”返回值,破费周折,而且代码很不好写.或者干脆绕过这道坎,走别的路了. 现在Java终于有可返回值的任务(也可以叫做线程)了. ...
- AdvStringGrid 滚动条问题
1.默认水平方向 滚动条是 小的 滚动的时候 数据会随着滚动 而 滚动的. 2.默认垂直方向 滚动条是 小的 滚动的时候 数据不会随着滚动 而滚动的.ScrollSynch := True; 垂直方向 ...
- HDU 2476 String painter(区间DP+思维)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2476 题目大意:给你字符串A.B,每次操作可以将一段区间刷成任意字符,问最少需要几次操作可以使得字符串 ...
- web文件<async-supported>错误分析
<async-supported>true</async-supported> 出现 cvc-complex-type.2.4.a: Invalid content was f ...
- 20165203《Java程序设计》第五周学习总结
教材学习内容总结 第七章 内部类 注意内部类和外嵌类的关系: 外嵌类的成员变量和方法在内部类有效 内部类的类体不可以声明static变量和方法.外嵌类的类体可以用内部类声明对象. 内部类仅供它的外嵌类 ...
- apache camel 条件路由
<camelContext xmlns="http://camel.apache.org/schema/blueprint"> <route id="e ...