链接
http://www.lydsy.com/JudgeOnline/problem.php?id=3993
题解
窝最近好笨啊...这样的水题都想不出来
二分答案+最大流判定,二分最短时间,判定这个时间内能否干掉所有机器人,直接改变S到每个激光炮的权值就行了,改成mid*B[i]。
代码
//二分答案+最大流
#include <cstdio>
#include <algorithm>
#include <cmath>
#define maxn 1000000
#define eps 1e-8
#define inf 1e60
using namespace std;
int N, M, A[maxn], B[maxn], head[maxn], to[maxn], tot=1, next[maxn], table[maxn],
num[maxn], Exit, d[maxn], S, T, last[maxn], sum;
double c[maxn];
void adde(int a, int b, double cc){to[++tot]=b;c[tot]=cc;next[tot]=head[a];head[a]=tot;}
int adde2(int a, int b, double cc){adde(a,b,cc);adde(b,a,0);return tot-1;}
double isap(int pos, double in)
{
double flow=0, x;
if(pos==T)return in;
for(int &p=last[pos];p;p=next[p])
{
if(fabs(c[p])>eps and d[to[p]]+1==d[pos])
{
flow+= x=isap(to[p],min(c[p],in-flow));
c[p]-=x, c[p xor 1]+=x;
if(fabs(flow-in)<eps or Exit)return flow;
}
}
Exit= --num[d[pos]]==0;
++num[++d[pos]];
last[pos]=head[pos];
return flow;
}
void input()
{
int i, j, x;
scanf("%d%d",&N,&M);
for(i=1;i<=N;i++)scanf("%d",A+i),sum+=A[i];
for(i=1;i<=M;i++)scanf("%d",B+i);
S=M+N+10, T=S+1;
for(i=1;i<=M;i++)
{
table[i]=adde2(S,i,inf);
for(j=1;j<=N;j++)
{
scanf("%d",&x);
if(x==1)adde2(i,M+j,inf);
}
}
for(i=1;i<=N;i++)adde2(M+i,T,A[i]);
}
int main()
{
double l, r, mid, flow;
int i, j;
input();
l=1.0, r=(double)sum, mid=(l+r)/2.0;
for(i=1;i<=100;i++)
{
for(j=2;j<=tot;j+=2)c[j]+=c[j^1], c[j^1]=0;
for(j=1;j<=M;j++)c[table[j]]=mid*B[j];
for(j=1;j<=T;j++)num[j]=d[j]=0;
for(Exit=flow=0;!Exit;flow+=isap(S,inf));
if(fabs(flow-(double)sum)<eps)r=mid;
else l=mid;
mid=(l+r)/2;
}
printf("%lf",mid);
return 0;
}