题目链接: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. 转:oracle:win7手工卸载oracle数据库11g

    环境:oracle 11g,win7,64bit 问题:oracle不正常安装.重新安装等情况需要卸载软件,然而oracle11g取消了界面卸载,改为deinstall.bat文件执行卸载.具体关于d ...

  2. 铁乐学python_day01-作业

    第一题:使用while循环输入 1 2 3 4 5 6 8 9 10 # 使用while循环输入 1 2 3 4 5 6 8 9 10 count = 0 while (True) : count = ...

  3. C# 算法题系列(一) 两数之和、无重复字符的最长子串

    题目一 原题链接 https://leetcode-cn.com/problems/two-sum/ 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整 ...

  4. September 30th 2017 Week 39th Saturday

    The simplest answer is often the correct one. 最简单的答案通常是最正确的答案. Simplest is always best. Sometimes yo ...

  5. 理解活在Iphone中的那些App (二)

    app是什么,为什么而存在 存在即合理的说法,已经被批臭批烂了.所以,作为一个程序员不能简简单单的因为上面来了一个需求,就完成一个需求.让做一个app就做一个app,只是简单的认为存在即合理,头让写就 ...

  6. python邮件处理

    SMTP SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式.Python对SMTP支持有 ...

  7. T440安装Win7系统

    于T440自带的是Win8系统,硬盘格式为GPT分区格式,而Win7必须要MRP格式,所以必须要将硬盘格式从GPT修改为MRP,方法如下: 准备工作,下载”电脑店U盘启动盘制作工具“(百度一下,去官网 ...

  8. 学习Android之SimpleAdapter显示网络图片

    效果图: 此程序基本的知识点是:SimpleAdapter本身是不支持网络图片的, 假设在Map.put(a,b)中 b为一个Bitmap,程序不会报红色字体,而是在控制台输出绿色的字体,例如以下 0 ...

  9. [源码分析]ArrayList

    add public boolean add(E e) { //先确保数组容量 ensureCapacityInternal(size + 1); //直接将值放在size位置 elementData ...

  10. virtualbox+vagrant学习-2(command cli)-5-vagrant halt命令

    Halt 格式: vagrant halt [options] [name|id] 该命令关闭vagrant管理的正在运行的机器. userdeMacBook-Pro:~ user$ vagrant ...