3993: [SDOI2015]星际战争

3993: [SDOI2015]星际战争

Time Limit: 10 Sec   Memory Limit: 128 MBSec   Special Judge
Submit: 1069   Solved: 489
[ Submit][ Status][ Discuss]

Description

 3333年,在银河系的某星球上,X军团和Y军团正在激烈地作战。在战斗的某一阶段,Y军团一共派遣了N个巨型机器人进攻X军团的阵地,其中第i个巨型机器人的装甲值为Ai。当一个巨型机器人的装甲值减少到0或者以下时,这个巨型机器人就被摧毁了。X军团有M个激光武器,其中第i个激光武器每秒可以削减一个巨型机器人Bi的装甲值。激光武器的攻击是连续的。这种激光武器非常奇怪,一个激光武器只能攻击一些特定的敌人。Y军团看到自己的巨型机器人被X军团一个一个消灭,他们急需下达更多的指令。为了这个目标,Y军团需要知道X军团最少需要用多长时间才能将Y军团的所有巨型机器人摧毁。但是他们不会计算这个问题,因此向你求助。

Input

第一行,两个整数,N、M。

第二行,N个整数,A1、A2…AN。
第三行,M个整数,B1、B2…BM。
接下来的M行,每行N个整数,这些整数均为0或者1。这部分中的第i行的第j个整数为0表示第i个激光武器不可以攻击第j个巨型机器人,为1表示第i个激光武器可以攻击第j个巨型机器人。

Output

 一行,一个实数,表示X军团要摧毁Y军团的所有巨型机器人最少需要的时间。输出结果与标准答案的绝对误差不超过10-3即视为正确。

Sample Input

2 2
3 10
4 6
0 1
1 1

Sample Output

1.300000

HINT

 【样例说明1】


战斗开始后的前0.5秒,激光武器1攻击2号巨型机器人,激光武器2攻击1号巨型机器人。1号巨型机器人被完全摧毁,2号巨型机器人还剩余8的装甲值;

接下来的0.8秒,激光武器1、2同时攻击2号巨型机器人。2号巨型机器人被完全摧毁。

对于全部的数据,1<=N, M<=50,1<=Ai<=105,1<=Bi<=1000,输入数据保证X军团一定能摧毁Y军团的所有巨型机器人


Source

[ Submit][ Status][ Discuss]



显然,如果答案为xs,那么在这段时间内每门激光炮一定是持续输出答案才能最优

考虑二分最终答案,那么每门激光炮能输出的伤害也就固定了,最大流验证即可

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;
 
const int maxm = 2E5 + 20;
typedef double DB;
const DB eps = 1E-5;
const DB EPS = 1E-8;
const DB INF = 1E12;
 
struct E{
    int to; DB cap,flow; E(){}
    E(int to,DB cap,DB flow): to(to),cap(cap),flow(flow){}
}edgs[maxm];
 
int n,m,s,t,cnt,cur[200],L[200],G[55][55];
DB tot,A[55],B[55];
 
vector <int> v[200];
queue <int> Q;
 
bool judge(const DB &x,const DB &y) {return fabs(x - y) <= EPS;}
void Add(int x,int y,DB cap)
{
    v[x].push_back(cnt); edgs[cnt++] = E(y,cap,0);
    v[y].push_back(cnt); edgs[cnt++] = E(x,0,0);
}
 
bool BFS()
{
    for (int i = s; i <= t; i++) L[i] = 0;
    L[s] = 1; Q.push(s);
    while (!Q.empty())
    {
        int k = Q.front(); Q.pop();
        for (int i = 0; i < v[k].size(); i++)
        {
            E e = edgs[v[k][i]];
            if (L[e.to] || judge(e.cap,e.flow)) continue;
            L[e.to] = L[k] + 1; Q.push(e.to);
        }
    }
    return L[t];
}
 
DB Dinic(int x,DB a)
{
    if (x == t) return a; DB flow = 0;
    for (int &i = cur[x]; i < v[x].size(); i++)
    {
        E &e = edgs[v[x][i]];
        if (L[e.to] != L[x] + 1 || judge(e.cap,e.flow)) continue;
        DB f = Dinic(e.to,min(a,e.cap - e.flow));
        if (judge(f,0.00)) continue; flow += f; e.flow += f;
        edgs[v[x][i]^1].flow -= f; a -= f;
        if (judge(a,0.00)) return flow;
    }
    if (judge(flow,0.00)) L[x] = -1; return flow;
}
 
bool Judge(DB now)
{
    for (int i = 1; i <= m; i++) Add(s,i,now * B[i]);
    for (int i = 1; i <= n; i++) Add(i + m,t,A[i]);
    for (int i = 1; i <= m; i++)
        for (int j = 1; j <= n; j++)
            if (G[i][j]) Add(i,j + m,INF);
     
    DB MaxFlow = 0;
    while (BFS())
    {
        for (int i = s; i <= t; i++) cur[i] = 0;
        MaxFlow += Dinic(s,INF);
    }
     
    for (int i = s; i <= t; i++) v[i].clear();
    cnt = 0; return judge(MaxFlow,tot);
}
 
int main()
{
    #ifdef DMC
        freopen("DMC.txt","r",stdin);
    #endif
     
    cin >> n >> m; s = 0; t = n + m + 1;
    for (int i = 1; i <= n; i++) scanf("%lf",&A[i]),tot += A[i];
    for (int i = 1; i <= m; i++) scanf("%lf",&B[i]);
    for (int i = 1; i <= m; i++)
        for (int j = 1; j <= n; j++) scanf("%d",&G[i][j]);
     
    DB l = 0,r = 1E8;
    while (r - l > eps)
    {
        DB mid = (l + r) / 2.00;
        if (Judge(mid)) r = mid; else l = mid;
    }
    printf("%.8f\n",(l + r) / 2.00);
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值