WA,求条
查看原帖
WA,求条
661984
Stone_Xz楼主2025/1/14 15:46

RT.

#include<bits/stdc++.h>
using namespace std;

const int N = 505;

int n, vis[N], h[N], ans, match[N], tim;

char x[N];

string m[N], e[N];

vector<int> nbr[N];

bool haha(int cur) {
	for (auto nxt : nbr[cur]) {
		if (vis[nxt] != tim) {
			vis[nxt] = tim;
			if (!match[nxt] || haha(match[nxt])) {
				match[nxt] = cur;
				return true;
			}
		}
	}
	return false;
}

void init() {
	ans = 0;
	tim = 1;
	for (int i = 1; i <= n; i++)
		nbr[i].clear();
}

void solve() {
	init();
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> h[i] >> x[i] >> m[i] >> e[i];
	for (int i = 1; i <= n; i++) if (x[i] == 'M') { 
		for (int j = 1; j <= n; j++) if (i != j) {
			if (abs(h[i] - h[j]) <= 40 && x[i] != x[j] && m[i] == m[j] && e[i] != e[j])
				nbr[i].push_back(j);
		}
	}
	for (int i = 1; i <= n; i++) {
		if (x[i] != 'M') continue;
		tim ++;
		if (haha(i)) ans ++;
	}
	cout << n - ans << "\n";
}

int main() {
	cin.tie(0) -> sync_with_stdio(0);
	int T; cin >> T;
	while (T--) solve();
	return 0;
}
2025/1/14 15:46
加载中...