首页 技术 正文
技术 2022年11月10日
0 收藏 650 点赞 4,374 浏览 1458 个字

题目链接: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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,118
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,590
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,435
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,206
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,842
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,927