mxqz,刚学OI,只拿了70pts
查看原帖
mxqz,刚学OI,只拿了70pts
406941
Register_int-std=c++14楼主2022/8/18 22:59

rt.推测可能是判断相交的时候寄掉了。

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN = 3010;
const int MAXM = MAXN * (MAXN - 1);

const int inf = 0x3f3f3f3f;

struct edge {
	int v, c, nxt;
} e[MAXM];

int head[MAXN], tot = 1;

void add(int u, int v, int c) {
    e[++tot] = { v, c, head[u] }, head[u] = tot;
    e[++tot] = { u, 0, head[v] }, head[v] = tot;
}

int level[MAXN];

int bfs(int s, int t) {
    memset(level, 255, sizeof level);
    queue<int> q;
    level[s] = 0, q.push(s);
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int i = head[u]; i; i = e[i].nxt) {
            if (e[i].c > 0 && level[e[i].v] < 0) {
                level[e[i].v] = level[u] + 1;
                q.push(e[i].v);
            }
        }
    }
    return level[t];
}

int dfs(int u, int t, int f) {
    if (u == t) return f;
    for (int i = head[u]; i; i = e[i].nxt) {
        if (e[i].c > 0 && level[u] < level[e[i].v]) {
            int d = dfs(e[i].v, t, min(f, e[i].c));
            if (d > 0) {
                e[i].c -= d, e[i ^ 1].c += d;
                return d;
            }
        }
    }
    return 0;
}

inline 
int max_flow(int s, int t) {
    int flow = 0, f;
    while (~bfs(s, t)) {
        while ((f = dfs(s, t, inf)) > 0) flow += f;
    }
    return flow;
}

struct circle {
	int x, y, r;
} a[MAXN];

struct rectangle {
	int ax, ay, bx, by;
} b[MAXN];

int tota, totb;

inline 
ll dis(ll ax, ll ay, ll bx, ll by) {
	return (ax - bx) * (ax - bx) + (ay - by) * (ay - by);
}

inline 
bool check(circle p, circle q) {
	return dis(p.x, p.y, q.x, q.y) <= (ll)(p.r + q.r) * (p.r + q.r);
}

inline 
bool check(rectangle p, rectangle q) {
	if (q.ax <= p.ax && p.ax <= q.bx && q.ay <= p.ay && p.ay <= q.by) return 1;
	if (q.ax <= p.bx && p.bx <= q.bx && q.ay <= p.ay && p.ay <= q.by) return 1;
	if (q.ax <= p.ax && p.ax <= q.bx && q.ay <= p.by && p.by <= q.by) return 1;
	if (q.ax <= p.bx && p.bx <= q.bx && q.ay <= p.by && p.by <= q.by) return 1;
	return 0;
}

inline 
bool check(circle p, int ax, int bx, int y, bool f) {
	if (f) swap(p.x, p.y);
	if (ax > p.x) return dis(ax, y, p.x, p.y) <= (ll)p.r * p.r;
	if (bx < p.x) return dis(bx, y, p.x, p.y) <= (ll)p.r * p.r;
	return abs(p.y - y) <= p.r;
}

inline 
bool check(circle p, rectangle q) {
	if (check(p, q.ax, q.bx, q.ay, 0)) return 1;
	if (check(p, q.ax, q.bx, q.by, 0)) return 1;
	if (check(p, q.ay, q.by, q.ax, 1)) return 1;
	if (check(p, q.ay, q.by, q.bx, 1)) return 1;
	return 0;
}

int n, s, t, k;

int x, y;

int main() {
    scanf("%d%d%d", &x, &y, &n), s = 0, t = n + 1;
    for (int i = 1; i <= n; i++) {
    	scanf("%d", &k);
    	if (k == 1) ++tota, scanf("%d%d%d", &a[tota].x, &a[tota].y, &a[tota].r);
    	else ++totb, scanf("%d%d%d%d", &b[totb].ax, &b[totb].ay, &b[totb].bx, &b[totb].by);
	}
	for (int i = 1; i <= tota; i++) {
		if (check(a[i], { 0, 0, x, 0 })) add(s, i, 1), add(i, s, 1);
	}
	for (int i = 1; i <= totb; i++) {
		if (check(b[i], { 0, 0, x, 0 })) add(s, tota + i, 1), add(tota + i, s, 1);
	}
	for (int i = 1; i <= tota; i++) {
		if (check(a[i], { 0, y, x, y })) add(i, t, 1), add(t, i, 1);
	}
	for (int i = 1; i <= totb; i++) {
		if (check(b[i], { 0, y, x, y })) add(tota + i, t, 1), add(t, tota + i, 1);
	}
	for (int i = 1; i <= tota; i++) {
		for (int j = i + 1; j <= tota; j++) {
			if (check(a[i], a[j])) add(i, j, 1), add(j, i, 1);
		}
		for (int j = 1; j <= totb; j++) {
			if (check(a[i], b[j])) add(i, tota + j, 1), add(tota + j, i, 1);
		}
	}
	for (int i = 1; i < totb; i++) {
		for (int j = i + 1; j <= totb; j++) {
			if (check(b[i], b[j])) add(tota + i, tota + j, 1), add(tota + j, tota + i, 1);
		}
	}
	printf("%d", max_flow(s, t));
}
2022/8/18 22:59
加载中...