[SDOI2015]星际战争

水题啦

网络流+二分
误差才10^-3,乱搞直接开longlong暴力每个都乘1000,输出时除一下就好了


# include <bits/stdc++.h>
# define IL inline
# define RG register
# define Fill(a, b) memset(a, b, sizeof(a))
# define Copy(a, b) memcpy(a, b, sizeof(a))
using namespace std;
typedef long long ll;
# define int ll
const int _(210), __(1e5 + 10), INF(1e18);

IL ll Read(){
    RG char c = getchar(); RG ll x = 0, z = 1;
    for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
    for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
    return x * z;
}

int sum, b[_], n, m, w[__], fst[_], nxt[__], to[__], cnt, tmp1[_], tmp2[__], tcnt;
int S, T, lev[_], cur[_], max_flow;
queue <int> Q;

IL void Add(RG int u, RG int v, RG int f){
    w[cnt] = f; to[cnt] = v; nxt[cnt] = fst[u]; fst[u] = cnt++;
    w[cnt] = 0; to[cnt] = u; nxt[cnt] = fst[v]; fst[v] = cnt++;
}

IL int Dfs(RG int u, RG int maxf){
    if(u == T) return maxf;
    RG int ret = 0;
    for(RG int &e = cur[u]; e != -1; e = nxt[e]){
        if(lev[to[e]] != lev[u] + 1 || !w[e]) continue;
        RG int f = Dfs(to[e], min(w[e], maxf - ret));
        ret += f; w[e ^ 1] += f; w[e] -= f;
        if(ret == maxf) break;
    }
    return ret;
}

IL bool Bfs(){
    Fill(lev, 0); lev[S] = 1; Q.push(S);
    while(!Q.empty()){
        RG int u = Q.front(); Q.pop();
        for(RG int e = fst[u]; e != -1; e = nxt[e]){
            if(lev[to[e]] || !w[e]) continue;
            lev[to[e]] = lev[u] + 1;
            Q.push(to[e]);
        }
    }
    return lev[T];
}

IL bool Check(RG int x){
    Copy(fst, tmp1); Copy(w, tmp2); cnt = tcnt;
    for(RG int i = 1; i <= m; ++i) Add(S, i + n, x * b[i]);
    for(max_flow = 0; Bfs(); ) Copy(cur, fst), max_flow += Dfs(S, INF);
    return max_flow == sum;
}
# undef int
int main(RG int argc, RG char* argv[]){
# define int ll
    n = Read(); m = Read(); Fill(fst, -1); T = n + m + 1;
    for(RG int i = 1, a; i <= n; ++i) a = Read() * 1000, Add(i, T, a), sum += a;
    for(RG int i = 1; i <= m; ++i) b[i] = Read();
    for(RG int i = 1; i <= m; ++i)
        for(RG int j = 1; j <= n; ++j)
            if(Read()) Add(i + n, j, INF);
    Copy(tmp1, fst); Copy(tmp2, w); tcnt = cnt;
    RG int l = 0, r = 1e8, ans = 0;
    while(l <= r){
        RG int mid = (l + r) >> 1;
        if(Check(mid)) ans = mid, r = mid - 1;
        else l = mid + 1;
    }
    printf("%.3lf\n", 1.0 * ans / 1000);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值