Test instructions: Jamie has a lot of contacts, but it is not easy to manage, he wants to put these contacts into groups, know that these contacts can be divided into which group, and require each group of contact person to the minimum, that is, there is an integer k, so that each group's contact number is not more than K, ask this k minimum is how much? Title Analysis: Multiple matching, two-point enumeration of all limit values. How do multiple matches match? If we have two sets X, y but y can match multiple x, this time we need to set a limit value for this match. For example, Y can match three x. If the matching value is less than three x we will match them until the limit is reached. Here Y to save all the matching x, if the match value is full, find () to match the line.
#include <stdio.h>#include<string.h>#include<algorithm>#include<iostream>#include<vector>#include<queue>#include<cmath>using namespacestd;#defineINF 0X3FFFFFFF#defineMAXN 1505intN, M;BOOLG[MAXN][MAXN], Vis[maxn];vector<vector<int> >Group;BOOLFind (intUintLIMT) { for(intI=0; i<m; i++) { if(G[u][i] &&!Vis[i]) {Vis[i]=true; if(Group[i].size () <LIMT) {group[i].push_back (U); return true; } for(intj=0; J < Group[i].size (); J + +) { if(Find (Group[i][j], LIMT)) {group[i].erase (Group[i].begin ()+K); Group[i].push_back (U); return true; } } } } return false;}BOOLSolveintLIMT) { intnum =0; Group.clear (); Group.resize (M+1); for(intI=0; i<n; i++) {memset (Vis,false,sizeof(VIS)); if(Find (i, LIMT)) Num++; } returnnum = =N;}intMain () {intA; Charch; while(SCANF ("%d%d", &n, &m), n+m) {memset (G,false,sizeof(G)); for(intI=0; i<n; i++) {scanf ("%*s"); while(1) { //GetChar ();scanf"%d%c", &a, &ch); G[i][a]=true; if(ch = ='\ n') Break; } } intL =0, R =N; while(L <R) {intMid = (L + R)/2; if(Solve (mid)) R=mid; ElseL= Mid +1; } printf ("%d\n", R); } return 0;}
POJ 2289Jamie ' s contact Groups (multiple match + two points)