栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3691 Flower

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3691 Flower

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cmath>#include <queue>using namespace std;const int N = 222;const int E = N * N;const int inf = 1111111111;struct edge {int u, v, c, f, nx;} ;int eh[N], tot;edge et[E];void add(int u, int v, int c, int f) {edge e = { u, v, c, f, eh[u]};et[tot] = e, eh[u] = tot++;}void addedge(int u, int v, int c) {add(u, v, c, 0), add(v, u, 0, 0);}int cur[N], cnt[N], dis[N], pre[N], low[N];void rebfs(int s, int t, int n) {for (int i = 0; i <= n; i++) {cnt[i] = 0, dis[i] = n;}queue<int> q;dis[t] = 0;cnt[0] = 1;q.push(t);while (!q.empty()) {int u = q.front();q.pop();for (int now = eh[u]; now != -1; now = et[now].nx) {if (et[now ^ 1].c == 0 || dis[et[now].v] < n) continue;dis[et[now].v] = dis[u] + 1;cnt[dis[et[now].v]]++;q.push(et[now].v);}}}int isap(int s, int t, int n) {rebfs(s, t, n);int u, v, now, i;for (i = 0; i <= n; i++) low[i] = 0;for (u = 0; u <= n; u++) cur[u] = eh[u];int flow = 0;u = s;low[s] = inf;while (dis[s] < n) {for (now = cur[u]; now != -1; now = et[now].nx) {if (et[now].c - et[now].f > 0 && dis[u] == dis[v = et[now].v] + 1) break;}if (now != -1) {cur[u] = now, pre[v] = now;low[v] = et[now].c - et[now].f;low[v] = min(low[v], low[u]);u = v;if (u == t) {for (; u != s; u = et[pre[u]].u) {et[pre[u]].f += low[t];et[pre[u] ^ 1].f -= low[t];}flow += low[t]; low[s] = inf;}} else {if (--cnt[dis[u]] == 0) break;dis[u] = n;cur[u] = eh[u];for (now = eh[u]; now != -1; now = et[now].nx) {if (et[now].c - et[now].f > 0 && dis[u] > dis[et[now].v] + 1) dis[u] = dis[et[now].v] + 1;}cnt[dis[u]]++;if (u != s) u = et[pre[u]].u;}}return flow;}void init() {tot = 0;memset(eh, -1, sizeof(eh));}struct Point {double x[3];} ;template<class T> T sqr(T x) { return x * x;}double dist(Point a, Point b) {double ret = 0;for (int i = 0; i < 3; i++) ret += sqr(a.x[i] - b.x[i]);return sqrt(ret);}const double EPS = 1e-8;double ds[N >> 1][N >> 1];int main() {int f[N >> 1], l[N >> 1], n;Point pt[N >> 1];while (cin >> n) {int sum = 0;memset(ds, 0, sizeof(ds));for (int i = 1; i <= n; i++) {for (int j = 0; j < 3; j++) cin >> pt[i].x[j];cin >> f[i] >> l[i];if (i != 1) sum += f[i];for (int j = 0; j < i; j++) {ds[i][j] = ds[j][i] = dist(pt[i], pt[j]);}}double L = 0, R = 1e6, m,res;bool yes = false;while (fabs(R - L) > EPS) {init();m = (L + R) / 2;addedge(1, n << 1 | 1, inf);for (int i = 2; i <= n; i++) {addedge(0, i, f[i]);addedge(i, i + n, l[i]);}for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) {if (i == j) continue;if (ds[i][j] < m) {addedge(i + n, j, inf);addedge(j + n, i, inf);}}}int tmp = isap(0, 2*n+1, 2*n+2);if (tmp >= sum){ yes=true; res=m; R = m;}else L = m;}if (yes) printf("%.7fn", res);else puts("-1");}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379662.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号