1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| #include <bits/stdc++.h> #define MAX_N 200 #define MAX_M 500000 #define INF 0x7f7f7f7f using namespace std; typedef double dnt; int n, m, k, s, t, mx, cnt, pr[MAX_N*2+5]; struct WIZ {int x, y, r, t;} wiz[MAX_N+5]; struct ELF {int x, y;} elf[MAX_N+5]; struct TRE {int x, y, r;} tre[MAX_N+5]; struct EDG {int u, v, c, nxt;} E[MAX_M+5]; int d[MAX_N*2+5], cr[MAX_N*2+5]; bool mrk[MAX_N+5][MAX_N+5];
WIZ operator - (WIZ a, TRE b) {WIZ t; t.x = a.x-b.x, t.y = a.y-b.y; return t;} WIZ operator - (TRE a, WIZ b) {WIZ t; t.x = a.x-b.x, t.y = a.y-b.y; return t;} ELF operator - (ELF a, TRE b) {ELF t; t.x = a.x-b.x, t.y = a.y-b.y; return t;} ELF operator - (ELF a, WIZ b) {ELF t; t.x = a.x-b.x, t.y = a.y-b.y; return t;} dnt dot(WIZ a, ELF b) {return a.x*b.x+a.y*b.y;} dnt cross(WIZ a, ELF b) {return a.x*b.y-a.y*b.x;} dnt dis(WIZ a, ELF b) {return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));} dnt dis(WIZ a, TRE b) {return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));} dnt dis(ELF a, TRE b) {return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));} dnt dis(WIZ a, ELF b, TRE p) { if (dot(a-p, b-p) > 0) return min(dis(a, p), dis(b, p)); return abs(cross(p-a, b-a)/dis(a, b)); } bool jud(int x, int y) { if (dis(wiz[x], elf[y]) > wiz[x].r) return false; for (int i = 1; i <= k; i++) if (dis(wiz[x], elf[y], tre[i]) < tre[i].r) return false; return true; }
void init() {s = 0, t = n+m+1, cnt = 0; memset(pr, -1, sizeof pr);} void insert(int u, int v, int c) {E[cnt].v = v, E[cnt].c = c, E[cnt].nxt = pr[u], pr[u] = cnt++;} void addedge(int u, int v, int c) {insert(u, v, c), insert(v, u, 0);} bool BFS() { queue <int> que; que.push(s); memset(d, -1, sizeof d), d[s] = 0; while (!que.empty()) { int u = que.front(); que.pop(); for (int i = pr[u]; ~i; i = E[i].nxt) { int v = E[i].v, c = E[i].c; if (!c || ~d[v]) continue; d[v] = d[u]+1, que.push(v); } } return ~d[t]; } int DFS(int u, int flow) { if (u == t) return flow; int ret = 0; for (int &i = pr[u]; ~i; i = E[i].nxt) { int v = E[i].v, c = E[i].c; if (!c || d[v] != d[u]+1) continue; int tmp = DFS(v, min(flow, c)); E[i].c -= tmp, E[i^1].c += tmp; flow -= tmp, ret += tmp; if (!flow) break; } if (!ret) d[u] = -1; return ret; } int Dinic() { int ret = 0; for (int i = s; i <= t; i++) cr[i] = pr[i]; while (BFS()) { ret += DFS(s, INF); for (int i = s; i <= t; i++) pr[i] = cr[i]; } return ret; }
bool chk(int tans) { init(); for (int i = 1; i <= n; i++) addedge(s, i, tans/wiz[i].t+1); for (int i = 1; i <= m; i++) addedge(i+n, t, 1); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (mrk[i][j]) addedge(i, j+n, 1); return Dinic() == m; } int bi_search(int l, int r) { int ret = -1; while (l <= r) { int mid = (l+r)>>1; if (chk(mid)) r = mid-1, ret = mid; else l = mid+1; } return ret; }
int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= n; i++) scanf("%d%d%d%d", &wiz[i].x, &wiz[i].y, &wiz[i].r, &wiz[i].t), mx = max(wiz[i].t, mx); for (int i = 1; i <= m; i++) scanf("%d%d", &elf[i].x, &elf[i].y); for (int i = 1; i <= k; i++) scanf("%d%d%d", &tre[i].x, &tre[i].y, &tre[i].r); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) mrk[i][j] = jud(i, j); return printf("%d", bi_search(0, m*mx)), 0; }
|