2271

1 // include file
2 #include <cstdio>
3 #include <cstdlib>
4 #include <cstring>
5 #include <cmath>
6 #include <cctype>
7 #include <ctime>
8
9 #include <iostream>
10 #include <sstream>
11 #include <fstream>
12 #include <iomanip>
13 #include <bitset>
14 #include <strstream>
15
16 #include <algorithm>
17 #include <string>
18 #include <vector>
19 #include <queue>
20 #include <set>
21 #include <list>
22 #include <functional>
23
24 using namespace std;
25
26 // typedef
27 typedef long long LL;
28 typedef unsigned long long ULL;
29
30 //
31 #define read freopen("in.txt","r",stdin)
32 #define write freopen("out.txt","w",stdout)
33 #define FORi(a,b,c) for(int i=(a);i<(b);i+=c)
34 #define FORj(a,b,c) for(int j=(a);j<(b);j+=c)
35 #define FORk(a,b,c) for(int k=(a);k<(b);k+=c)
36 #define FORp(a,b,c) for(int p=(a);p<(b);p+=c)
37
38 #define FF(i,a) for(int i=0;i<(a);i+++)
39 #define FFD(i,a) for(int i=(a)-1;i>=0;i--)
40 #define Z(a) (a<<1)
41 #define Y(a) (a>>1)
42
43 const double eps = 1e-6;
44 const double INFf = 1e10;
45 const int INFi = 1000000000;
46 const double Pi = acos(-1.0);
47
48 template<class T> inline T sqr(T a){return a*a;}
49 template<class T> inline T TMAX(T x,T y)
50 {
51 if(x>y) return x;
52 return y;
53 }
54 template<class T> inline T TMIN(T x,T y)
55 {
56 if(x<y) return x;
57 return y;
58 }
59 template<class T> inline void SWAP(T &x,T &y)
60 {
61 T t = x;
62 x = y;
63 y = t;
64 }
65 template<class T> inline T MMAX(T x,T y,T z)
66 {
67 return TMAX(TMAX(x,y),z);
68 }
69
70
71 // code begin
72 int T,N;
73 #define MAXN 510
74 struct node
75 {
76 int h;
77 int sex;
78 char mu[110];
79 char sp[110];
80 };
81 node st[MAXN];
82 node boy[MAXN];
83 node girl[MAXN];
84 int bs;
85 int gs;
86 vector<int> G[MAXN];
87 int mt[MAXN];
88 bool used[MAXN];
89
90 bool Cancouple(int i,int j)
91 {
92 if( abs(boy[i].h-girl[j].h)>40) return false;
93 if( strcmp(boy[i].mu,girl[j].mu)!=0) return false;
94 if( strcmp(boy[i].sp,girl[j].sp)==0) return false;
95 return true;
96 }
97 bool hungarian_MM(int i)
98 {
99 FORj(0,G[i].size(),1)
100 {
101 if(!used[ G[i][j] ])
102 {
103 used[ G[i][j] ] =1;
104 if( mt[ G[i][j] ]==-1 || hungarian_MM(mt[G[i][j]]))
105 {
106 mt[ G[i][j] ] = i;
107 return true;
108 }
109 }
110 }
111 return false;
112 }
113 int main()
114 {
115
116 int ans;
117 char sx[10];
118 scanf("%d",&T);
119 while(T--)
120 {
121 scanf("%d",&N);
122 FORi(0,N,1)
123 {
124 scanf("%d%s%s%s",&st[i].h,sx,st[i].mu,st[i].sp);
125 if(sx[0]=='M')
126 st[i].sex = 1;
127 else
128 st[i].sex=2;
129 }
130
131 bs = 0;
132 gs = 0;
133 FORi(0,N,1)
134 {
135 if( st[i].sex==1)
136 boy[bs++] = st[i];
137 else
138 girl[gs++] = st[i];
139 }
140
141
142
143 FORi(0,bs,1)
144 {
145 G[i].clear();
146 FORj(0,gs,1)
147 {
148 //if(i==j) continue;
149 if( Cancouple(i,j))
150 G[i].push_back(j);
151 }
152 }
153
154 memset(mt,-1,sizeof(int)*MAXN);
155 ans = 0;
156 FORi(0,bs,1)
157 {
158 memset(used,0,sizeof(bool)*MAXN);
159 if( hungarian_MM(i))
160 ans++;
161 }
162 printf("%d\n",N-ans);
163 }
164 return 0;
165 }
posted @ 2011-03-05 22:34  AC2012  阅读(216)  评论(0编辑  收藏  举报