bzoj3993: [SDOI2015]星际战争

链接

  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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值