Test instructions
Given a list of size n, to put the list of people into the M group, given the possible number of each person, you need to determine a distribution scheme, so that the largest group of the smallest.
Ideas:
Multi-matching of binary graphs
If the group is not full, go to that group.
If it's full, kick one out of that group.
If you can kick it out, kick it out and put the current in it.
If all the groups that can reach are not kicked out, it's not right.
As for the largest specific value, two minutes is OK.
/************************************************author:d evilcreated time:2016/5/17 17:56:52***************** ******************************* */#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<cmath>#include<stdlib.h>using namespacestd;Const intn=1010;Const intm=510;intn,m,mid,x;Chars[ -];BOOLVis[m];vector<int>Eg[n],isin[m];BOOLFind (intu) { for(intI=0; I<eg[u].size (); i++) { intv=Eg[u][i]; if(!Vis[v]) {Vis[v]=1; if(Isin[v].size () <mid) {isin[v].push_back (U); return 1; } for(intj=0; J<isin[v].size (); j + +) { if(Find (Isin[v][j])) {Isin[v][j]=T; return 1; } } } } return 0;}BOOLMaxmatch () { for(intI=0; i<m;i++) isin[i].clear (); for(intI=0; i<n;i++) {memset (Vis,0,sizeof(VIS)); if(! Find (i))return 0; } return 1;}intMain () {//freopen ("In.txt", "R", stdin); while(~SCANF ("%d%d", &n,&m) && (n+m)) { for(intI=0; i<n;i++) eg[i].clear (); for(intI=0; i<n;i++) {scanf ("%s", s); while(SCANF ("%d", &x) = =1) {eg[i].push_back (x); if(GetChar () = ='\ n') Break; } } intL=0, r=N; while(l<=r) {Mid= (l+r) >>1; if(Maxmatch ()) r=mid-1; ElseL=mid+1; } printf ("%d\n", L); } return 0;}
POJ2289 Jamie's Contact Groups (two-figure multi-match)