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 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- 6for Java
class Check{ public boolean validate(String name, String password){ if(name.equals("xuzhaoni ...
- vue-component=>v-on
$emit 返回 shouldPropagate,shouldPropagate 是一个布尔值,取决于父链上的是否存在该事件的监听器以及,事件处理程序返回的值.他决定 $dispatch 是否停止冒泡 ...
- 虚拟机CentOS7.2 1611 Minimal最小化安装后桥接固定ip
ip addr show 或者 ip addr 或者 ip a vim /etc/sysconfig/network-scripts/ifcfg-ens33 根据 然后重启网卡 service net ...
- javascript中window.location.search方法简介
window.location.search方法是截取当前url中"?"后面的字符串,示例如下: 例如:http://www.firefoxchina.cn/?ntab截取后的字符 ...
- [洛谷P4722]【模板】最大流 加强版 / 预流推进
会$TLE$... C++ Code:(HLPP) #pragma GCC optimize(3) #pragma GCC optimize("unroll-loops") #in ...
- 在C/C++函数中使用可变参数
原文链接地址:http://blog.csdn.net/djinglan/article/details/8425768 下面介绍在C/C++里面使用的可变参数函数. 先说明可变参数是什么,先回顾一下 ...
- CSS网页宽度怎么定比较合适
设计网页的时候,确定宽度是一件很苦恼的事.以nowamagic.net为例,根据Google Analytics的统计,半年多以来,访问者的屏幕分辨率一共有81种.最小的分辨率是122x160,这应该 ...
- 如何用listview显示服务端数据
https://www.cnblogs.com/caobotao/p/5061627.html
- C. Annoying Present SB题
C. Annoying Present time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- php-instanceof运算符
1.关于 instanceof 的一些基本概念 1).instanceof 用于确定一个PHP变量是否属于某一类class的实例: <?php class MyClass { } class N ...