Codeforces 912 D. Fishes (贪心、bfs)
题目链接: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)的更多相关文章
- codeforces 704B - Ant Man 贪心
codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...
- CodeForces - 50A Domino piling (贪心+递归)
CodeForces - 50A Domino piling (贪心+递归) 题意分析 奇数*偶数=偶数,如果两个都为奇数,最小的奇数-1递归求解,知道两个数都为1,返回0. 代码 #include ...
- 贪心+bfs 或者 并查集 Codeforces Round #268 (Div. 2) D
http://codeforces.com/contest/469/problem/D 题目大意: 给你一个长度为n数组,给你两个集合A.B,再给你两个数字a和b.A集合中的每一个数字x都也能在a集合 ...
- codeforces 814 D. An overnight dance in discotheque (贪心+bfs)
题目链接:http://codeforces.com/contest/814/problem/D 题意:给出奇数个舞者,每个舞者都有中心坐标和行动半径,而且这些点组成的园要么相互包含要么没有交集求,讲 ...
- #292 (div.2) D.Drazil and Tiles (贪心+bfs)
Description Drazil created a following problem about putting × tiles into an n × m grid: "The ...
- codeforces 1283D. Christmas Trees(bfs)
链接: https://codeforces.com/contest/1283/problem/D 题意:给定n个不同的整数点,让你找m个不同的整数点,使得这m个点到到这n个点最小距离之和最小. 思路 ...
- Codeforces 161 B. Discounts (贪心)
题目链接:http://codeforces.com/contest/161/problem/B 题意: 有n个商品和k辆购物车,给出每个商品的价钱c和类别t(1表示凳子,2表示铅笔),如果一辆购物车 ...
- CodeForces 176A Trading Business 贪心
Trading Business 题目连接: http://codeforces.com/problemset/problem/176/A Description To get money for a ...
- Codeforces Gym 100803C Shopping 贪心
Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopp ...
随机推荐
- 18c新特性的一些小结(from JimmyHe)
Oracle 18c在2018-02-16 release出来的,还是秉承着Oracle的cloud first理念,18c现在cloud和Engineered Systems上推出,想在传统的机器上 ...
- 用path动画绘制水波纹
用path动画绘制水波纹 效果 源码 // // ViewController.m // PathAnimation // // Created by YouXianMing on 15/7/3. / ...
- Loadrunner11代理录制&各个常见功能介绍
1.代理录制: Lr代理工具:C:\Program Files (x86)\HP\LoadRunner\bin\wplus_init_wsock.exe 1) 设置代理 配置代理信息: 2)设置浏览器 ...
- $.ajax 在请求没有完成,是可以往下继续执行js代码的
$.ajax({ url:url, data:{}, success:function(arr) { var varHtml='<option value="" checke ...
- C# 算法题系列(一) 两数之和、无重复字符的最长子串
题目一 原题链接 https://leetcode-cn.com/problems/two-sum/ 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整 ...
- Windows程序设计(Charles Petzold)HELLOWIN程序实现
/*-------------------------------------------------------------- HELLOWIN.C--DisPlays "Hello, W ...
- 玩Web虎-运行时受保护文件不可复制
1. 直接复制粘贴,提示“操作无法完成,因为文件已在system中打开” 2.拔下加密锁后,复制粘贴,依然上错 3.用NoVirusThanks的 kernel-mode driver loader ...
- centos安装不上的问题
Installing VMware Tools, please wait...mount: special device /dev/hda does not existmount: block dev ...
- 【洛谷】【二分答案+贪心】P1316 丢瓶盖
[题目描述:] 陶陶是个贪玩的孩子,他在地上丢了A个瓶盖,为了简化问题,我们可以当作这A个瓶盖丢在一条直线上,现在他想从这些瓶盖里找出B个,使得距离最近的2个距离最大,他想知道,最大可以到多少呢? [ ...
- Jenkins启动和停止服务
1.怎么启动Jenkins? step1:进入到Jenkins的war包所在的目录. 如果是win7及以上版本,直接打开Jenkins的war包所在的目录,在地址栏敲cmd,回车. 上述结果和进入cm ...