题目链接:Fishes

题意:

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

题解:

  这题dfs我是真的没想到。。因为怎么说,总是感觉这样有些暴力吧@。@# 要好好反思了。这题首先要把每个位置网覆盖的次数的公式推出来(用if else也行其实),因为可以发现最中间的位置一定最大,所以选取最中间的位置开始bfs,把遇到的点都放到优先队列中,这里对优先队列进行符号重载就可以很好地解决排序的问题,很值得学习。

 #include<bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5+;
long long N,M,r,k;
struct P
{
long long first,second;
P(int x,int y){first = x,second = y;}
};
priority_queue <P> que;
set<int> st[MAX_N];
long long get_val(P t)
{
return (min(N - r + , t.first) - max(1ll, t.first - r + ) + ) * (min(M - r + , t.second) - max(1ll, t.second - r + ) + );
}
bool operator < (const P &a,const P &b)
{
return get_val(b) > get_val(a);
} int main()
{
while(cin>>N>>M>>r>>k)
{
while(!que.empty()) que.pop();
for(int i=;i<MAX_N;i++) st[i].clear();
int x = (N+)/;
int y = (M+)/;
que.push(P(x,y));
st[x].insert(y);
double ans = ;
long long num = ;
while(!que.empty())
{
P t = que.top();que.pop();
ans += (get_val(t)*1.0)/((N-r+)*(M-r+)*1.0);
k--;
if(!k) break;
//cout<<t.first<<"..."<<t.second<<"...."<<get_val(t)<<endl;
if(t.first+> && t.first+<=N && st[t.first+].count(t.second) == ) que.push(P(t.first+,t.second)),st[t.first+].insert(t.second);
if(t.first-> && t.first-<=N && st[t.first-].count(t.second) == ) que.push(P(t.first-,t.second)),st[t.first-].insert(t.second);
if(t.second- > && t.second- <=M && st[t.first].count(t.second-) == ) que.push(P(t.first,t.second-)),st[t.first].insert(t.second-);
if(t.second+ > && t.second+ <=M && st[t.first].count(t.second+) == ) que.push(P(t.first,t.second+)),st[t.first].insert(t.second+);
}
printf("%.10lf\n",ans);
}
return ;
}

Codeforces 912 D. Fishes (贪心、bfs)的更多相关文章

  1. codeforces 704B - Ant Man 贪心

    codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...

  2. CodeForces - 50A Domino piling (贪心+递归)

    CodeForces - 50A Domino piling (贪心+递归) 题意分析 奇数*偶数=偶数,如果两个都为奇数,最小的奇数-1递归求解,知道两个数都为1,返回0. 代码 #include ...

  3. 贪心+bfs 或者 并查集 Codeforces Round #268 (Div. 2) D

    http://codeforces.com/contest/469/problem/D 题目大意: 给你一个长度为n数组,给你两个集合A.B,再给你两个数字a和b.A集合中的每一个数字x都也能在a集合 ...

  4. codeforces 814 D. An overnight dance in discotheque (贪心+bfs)

    题目链接:http://codeforces.com/contest/814/problem/D 题意:给出奇数个舞者,每个舞者都有中心坐标和行动半径,而且这些点组成的园要么相互包含要么没有交集求,讲 ...

  5. #292 (div.2) D.Drazil and Tiles (贪心+bfs)

    Description Drazil created a following problem about putting  ×  tiles into an n × m grid: "The ...

  6. codeforces 1283D. Christmas Trees(bfs)

    链接: https://codeforces.com/contest/1283/problem/D 题意:给定n个不同的整数点,让你找m个不同的整数点,使得这m个点到到这n个点最小距离之和最小. 思路 ...

  7. Codeforces 161 B. Discounts (贪心)

    题目链接:http://codeforces.com/contest/161/problem/B 题意: 有n个商品和k辆购物车,给出每个商品的价钱c和类别t(1表示凳子,2表示铅笔),如果一辆购物车 ...

  8. CodeForces 176A Trading Business 贪心

    Trading Business 题目连接: http://codeforces.com/problemset/problem/176/A Description To get money for a ...

  9. Codeforces Gym 100803C Shopping 贪心

    Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopp ...

随机推荐

  1. asp.net MVC4 框架揭秘 读书笔记系列1

    1.1 传统MVC 名词解释 Autonomous View. AV. 自制视图 GUI图形用户界面(Graphical User Interface,简称 GUI,又称图形用户接口)是指采用图形方式 ...

  2. yii 验证码功能的实现

    首先知晓我们在使用验证码的时候通常是和我们的表单小部件配合使用首先我们创建model层 新建一个php文件 名字叫做Verifycode.php 要在我们的model层 创建我们的验证码的验证规则,我 ...

  3. Windows Server 2008搭建域控制器

    前言 1.为什么要建域 工作组的分散管理模式不适合大型的网络环境下工作,域模式就是针对大型的网络管理需求设计的,就是共享用户账号,计算机账号和安全策略的计算机集合.域中集中存储用户账号的计算机就是域控 ...

  4. 一、TCL事务控制语言 二、MySQL中的约束 三、多表查询(重点) 四、用户的创建和授权 五、MySQL中的索引

    一.TCL事务控制语言###<1>事务的概念 事务是访问并可能更新数据库中各种数据项的执行单元. 事务是一条SQL语句,一组SQL语句,或者整个程序. 事务是恢复和并发控制的基本单位. 事 ...

  5. UI(二)之正式过程

    2018-12-04 09:48:25 1.SetWindowsHookEx ·钩子实际上是一个处理消息的程序段,通过系统调用,把它挂入系统.每当特定的消息发出,在没有到达目的窗口前,钩子程序就先捕获 ...

  6. XtraEditors二、ComboBox、ComboBoxEdit、CheckedComboBoxEdit

    https://documentation.devexpress.com/WindowsForms/DevExpress.XtraEditors.ComboBoxEdit.class 1.使用Winf ...

  7. IO多路复用(select)

    select在操作系统内部,维护了一个for循环,检测对象是否变化.select在各种平台都可使用,但效率不高.select对监听的个数是有限制的(1024) poll与select相同,但是没有监听 ...

  8. VMWare虚拟机下为Windows Server 2012配置静态IP(NAT方式)

    利用VMWare Workstation安装了Windows Server 2012 R2, 对于服务器来说,使用动态分配的IP会很不方便,最好设置为静态IP,此例中虚拟机和主机的网络联接方式为NAT ...

  9. ali验证码推送接口调用

    /** * 发送接口 * @param $info 发送信息的某些参数 * @return bool */ public function send($info) { $config = target ...

  10. 【转】Android 旋转动画,停止和持续旋转

    旋转180度后停止 RotateAnimation rotate; rotate =new RotateAnimation(0f,180f,Animation.RELATIVE_TO_SELF, 0. ...