官方题解是一个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的更多相关文章

  1. Codeforces.739E.Gosha is hunting(DP 带权二分)

    题目链接 \(Description\) 有\(n\)只精灵,两种精灵球(高级和低级),每种球能捕捉到第\(i\)只精灵的概率已知.求用\(A\)个低级球和\(B\)个高级球能捕捉到精灵数的最大期望. ...

  2. codeforces 739E - Gosha is hunting

    这道题有三种做法,感受一下: 感觉到了歪果仁费尽脑汁想出来的神仙贪心脑洞题被中国人套路算法踩爆的凄凉...(我的名字是不是暴露了我的真实实力) ============================ ...

  3. HZOJ 赤(CF739E Gosha is hunting)

    本来没有打算写题解的,时间有点紧.但是这个wqs二分看了好久才明白还是写点东西吧. 题解就直接粘dg的了: 赤(red) 本题来自codeforces 739E,加大了数据范围. 首先对一只猫不会扔两 ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. 基于C#的PISDK研究(理论)

    本篇文章主要对PISDK体系结构以及重点类进行阐述. 当我们决定使用PISDK时,可能会使用到下面的类库: 在上表中,PISDK.dll为核心类,大部分主要功能都在该类中.PISDKCommon.dl ...

  2. ui-grid表格怎么实现内容居中

    这次是思想落后了,只关注怎么使用原生的ui-grid样式来实现这一需求,后来发现可以通过此列的cellTemplate来为列指定内容,从而可以使用css调整样式. ps:其实有时候换种思路,豁然开朗. ...

  3. maven中进行go的编译

    maven提供的插件maven-antrun-plugin真是个好东东,使得maven可以利用ant的很多功能. 最近需要实现在maven中实现对go代码的编译,添加如下代码在pom文件中即可. &l ...

  4. input标签与label标签的“合作关系”

    一直忽略了input和label的关系.一次在做自定义单选框的时候又重新捡起来这对“兄弟”. label的for属性和input的id值一致的话,input和label就会组成一个组.例如: < ...

  5. C++——拷贝构造函数说明

    一. 什么是拷贝构造函数 首先对于普通类型的对象来说,它们之间的复制是很简单的,例如: [c-sharp] view plaincopy 1 int a = 100; 2 int b = a; 而类对 ...

  6. POJ1417:True Liars(DP+带权并查集)

    True Liars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. Equal Sums (map的基本应用) 多学骚操作

    C. Equal Sums time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  8. ACM模板~求第k短路 ~~~A*+Dijkstra

    #include <map> #include <set> #include <cmath> #include <ctime> #include < ...

  9. Spring 学习笔记(一)

    一.Spring 是什么? •Spring 是一个开源框架. •Spring 为简化企业级应用开发而生. 使用 Spring 可以使简单的 JavaBean 实现以前只有 EJB 才能实现的功能. • ...

  10. 记录一次Nginx跳转报错的问题

    错误信息如下: An error occurred. Sorry, the page you are looking for is currently unavailable. Please try ...