老师在选择一些学生做活动时,为避免学生发生暧昧关系,就提出了四个要求。在他眼中,只要任意两个人符合这四个要求之一,就不可能发生暧昧。现在给出n个学生关于这四个要求的信息,求老师可以挑选出的最大学生数量。
#include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <set> #include <vector> #include <stack> #include <queue> #include <algorithm> #include <cmath> #define rap(i, a, n) for(int i=a; i<=n; i++) #define MOD 2018 #define LL long long #define ULL unsigned long long #define Pair pair<int, int> #define mem(a, b) memset(a, b, sizeof(a)) #define _ ios_base::sync_with_stdio(0),cin.tie(0) //freopen("1.txt", "r", stdin); using namespace std; const int maxn = 1010, INF = 0x7fffffff; int n; int line[maxn][maxn], girl[maxn], used[maxn]; struct node { int h; char s; string music, sports; }Node[maxn]; bool find(int x) { for(int i=1; i<=n; i++) { if(line[x][i] && !used[i]) { used[i] = 1; if(!girl[i] || find(girl[i])) { girl[i] = x; return 1; } } } return 0; } int main() { int T; scanf("%d", &T); while(T--) { int res = 0; mem(girl, 0); mem(line, 0); scanf("%d", &n); rap(i, 1, n) { cin>> Node[i].h >> Node[i].s >> Node[i].music >> Node[i].sports; } rap(i, 1, n) rap(j, i+1, n) { if(abs(Node[i].h - Node[j].h) <= 40 && Node[i].s != Node[j].s && Node[i].music == Node[j].music && Node[i].sports != Node[j].sports) { line[i][j] = line[j][i] = 1; } } rap(i, 1, n) { mem(used, 0); if(find(i)) res++; } printf("%d ", n - res/2); } return 0; }