POJ 2289Jamie ' s contact Groups (multiple match + two points)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.