WA 90pts
查看原帖
WA 90pts
241100
Emertyst楼主2022/12/22 14:56

#7 总是输出 1349.8900001349.890000(答案是 1349.8888891349.888889

#include <cstring>
#include <iostream>
#include <queue>
#define TO(x) edge[x].to
#define W(x) edge[x].w
#define NXT(x) edge[x].nxt
using namespace std;
typedef long long ll;
const int MAXN0 = 55, MAXN1 = 105, MAXN2 = 3e4 + 5;
const ll INF = 1ll << 50, T = 1e5;
const double EPS = 1e-4;
int n, m, s, t, sum, a[MAXN0], b[MAXN0];
bool c[MAXN0][MAXN0];
double ans;
class Graph {
private:
    struct Edge {
        int to, nxt;
        ll w;
        Edge() {}
        Edge(int to, ll w, int nxt) : to(to), w(w), nxt(nxt) {}
    };
    int tot, dep[MAXN1], cur[MAXN1], head[MAXN1];
    Edge edge[MAXN2 << 1];
    queue<int> q;
    bool bfs() {
        memset(dep, 0, sizeof(dep)), memcpy(cur, head, sizeof(cur));
        while (!q.empty())
            q.pop();
        for (dep[s] = 1, q.emplace(s); !q.empty(); q.pop())
            for (int e = head[q.front()]; e; e = NXT(e))
                if (W(e) && !dep[TO(e)]) {
                    dep[TO(e)] = dep[q.front()] + 1, q.emplace(TO(e));
                    if (TO(e) == t)
                        return true;
                }
        return false;
    }
    ll dfs(int x, ll flow) {
        if (x == t)
            return flow;
        ll now = flow;
        for (int &e = cur[x]; e; e = NXT(e))
            if (W(e) && dep[TO(e)] == dep[x] + 1) {
                ll f = dfs(TO(e), min(W(e), now));
                W(e) -= f, W(e ^ 1) += f, now -= f;
                if (!now)
                    break;
            }
        return flow - now;
    }

public:
    Graph() { tot = 1; }
    void clear() { tot = 1, memset(head, 0, sizeof(head)); }
    void addEdge(int u, int v, ll w) {
        edge[++tot] = Edge(v, w, head[u]), head[u] = tot;
        edge[++tot] = Edge(u, 0, head[v]), head[v] = tot;
    }
    ll solve() {
        ll ans = 0;
        while (bfs())
            ans += dfs(s, INF);
        return ans;
    }
} graph;
int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n >> m, s = m + n + 1, t = s + 1;
    for (int i = 1; i <= n; ++i)
        cin >> a[i], sum += a[i];
    for (int i = 1; i <= m; ++i)
        cin >> b[i];
    for (int i = 1; i <= m; ++i)
        for (int j = 1; j <= n; ++j)
            cin >> c[i][j];
    for (double l = 0, r = sum; r - l > EPS; graph.clear()) {
        ans = (l + r) / 2;
        ll tmp = ans * T;
        for (int i = 1; i <= m; ++i)
            graph.addEdge(s, i, tmp * b[i]);
        for (int i = 1; i <= n; ++i)
            graph.addEdge(m + i, t, T * a[i]);
        for (int i = 1; i <= m; ++i)
            for (int j = 1; j <= n; ++j)
                if (c[i][j])
                    graph.addEdge(i, m + j, INF);
        if (graph.solve() == T * sum)
            r = ans;
        else
            l = ans;
    }
    cout << ans << "\n";
}
2022/12/22 14:56
加载中...