codeforces 739E
官方题解是一个n2logn的dp做法
不过有一个简单易想的费用流做法
对每个小精灵,连边(A,i,1,pi) (B,i,1,ui) (i,t,1,0) (i,t,1,-pi*ui)
最后连边(s,A,a,0) (s,B,b,0)
跑最大费用最大流即可,注意精度误差
#include<bits/stdc++.h> using namespace std; struct way{int po,next,flow;double cost;} e[];
const double eps=1e-;
int pre[],p[],cur[],q[];
double d[],c[];
bool v[];
int len,n,m,a,b,t; void add(int x,int y,int f,double c)
{
e[++len].po=y;
e[len].flow=f;
e[len].cost=c;
e[len].next=p[x];
p[x]=len;
} void build(int x,int y,int f,double c)
{
add(x,y,f,c);
add(y,x,,-c);
} bool spfa()
{
for (int i=; i<=t; i++) d[i]=-1e20;
memset(v,,sizeof(v));
d[]=;
int f=,r=;q[]=;
while (f<=r)
{
int x=q[f++];
v[x]=;
for (int i=p[x]; i!=-; i=e[i].next)
{
int y=e[i].po;
if (e[i].flow&&d[x]+e[i].cost-eps>d[y])
{
d[y]=d[x]+e[i].cost;
pre[y]=x; cur[y]=i;
if (!v[y])
{
q[++r]=y;
v[y]=;
}
}
}
}
return d[t]>-1e20;
} double cost()
{
double s=;
while (spfa())
{
s+=d[t];
for (int i=t; i; i=pre[i])
{
int j=cur[i];
e[j].flow--;
e[j^].flow++;
}
}
return s;
} int main()
{
len=-;
memset(p,,sizeof(p));
scanf("%d%d%d",&n,&a,&b);
t=n+;
for (int i=; i<=n; i++)
{
scanf("%lf",&c[i]);
build(n+,i,,c[i]);
build(i,t,,);
}
for (int i=; i<=n; i++)
{
double x;
scanf("%lf",&x);
build(n+,i,,x);
build(i,t,,-c[i]*x);
}
build(,n+,a,);
build(,n+,b,);
printf("%.5lf\n",cost());
}
codeforces 739E的更多相关文章
- Codeforces.739E.Gosha is hunting(DP 带权二分)
题目链接 \(Description\) 有\(n\)只精灵,两种精灵球(高级和低级),每种球能捕捉到第\(i\)只精灵的概率已知.求用\(A\)个低级球和\(B\)个高级球能捕捉到精灵数的最大期望. ...
- codeforces 739E - Gosha is hunting
这道题有三种做法,感受一下: 感觉到了歪果仁费尽脑汁想出来的神仙贪心脑洞题被中国人套路算法踩爆的凄凉...(我的名字是不是暴露了我的真实实力) ============================ ...
- HZOJ 赤(CF739E Gosha is hunting)
本来没有打算写题解的,时间有点紧.但是这个wqs二分看了好久才明白还是写点东西吧. 题解就直接粘dg的了: 赤(red) 本题来自codeforces 739E,加大了数据范围. 首先对一只猫不会扔两 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- 下拉框select chosen被遮盖
最简单的就是让容器高度大点. 用js调整也行. 为什么z-index不管事,看下面... 浏览器支持 所有主流浏览器都支持 z-index 属性. 注释:任何的版本的 Internet Explore ...
- hdu 3231 Box Relations (拓扑排序)
Box Relations Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- BZOJ2286 [Sdoi2011]消耗战 【虚树 + 树形Dp】
2286: [Sdoi2011]消耗战 Time Limit: 20 Sec Memory Limit: 512 MB Submit: 4261 Solved: 1552 [Submit][Sta ...
- 【NOIP 模拟赛】中值滤波 打表找规律
对于这样看起来不像什么算法也没什么知识点的题,一脸懵逼的话不是手推规律就是打表找规律......... 当然还有一些超出你能力之外的数学题...... #include <cstdio> ...
- 如何用JavaScript做一个可拖动的div层
可拖动的层在Web设计中用处很多,比如在某些需要自定义风格布局的应用中,控件就需要拖动操作,下面介绍一个,希望可以满足你的需求,顺便学习一下可拖动的层是如何实现的. 下面是效果演示: 这个DIV可以移 ...
- [模拟赛] StopAllSounds
Description 小松鼠开心地在树之间跳跃着,突然她停了下来.因为眼前出现了一个 拿着专克超萌小松鼠的法宝----超萌游戏机的游客! 超萌游戏机之所以拥有这个名字,是因为它的屏幕是一个n × 2 ...
- 清理/var/spool/clientmqueue目录释放大量空间
清理/var/spool/clientmqueue目录可以释放大量空间,具体命令是:ls | xargs rm -f 文件太大,rm -rf会由于参数太多而无法删除,所以需要用上面的命令. “Argu ...
- Join to domain powershell script
Join to domain powershell script $username = "domain\admin" $Password = "xxxxxxxx&quo ...
- 关于控制下拉框select只读的js控制
文本框有readonly属性,直接设置:下拉框没有readonly属性,也不能通过其他属性进行只读的设置,下拉框只有disabled属性,但是这个属性设成true之后,值就获取不到了: 我在网上搜了一 ...
- 谈数据中心SDN与NFV
看到一篇谈论SDN与NFV的文章,分析的还不错,贴过来方便自己后续查阅: http://network.chinabyte.com/175/13095675.shtml 论数据中心SDN与NFV技术关 ...