POJ 3189Steady Cow Assignment

Source: Internet
Author: User

Test instructions: Each cow has a ranking (according to the level of liking), each cow can be accommodated in the number of cattle have a limit, re-assigned to the cattle barn, so that the cattle in the cow's heart of the poor ranking (the largest ranking and the lowest ranking of all cattle) the smallest. Title input: First is two number n, B is for n cow B cattle barn The next first row, B, represents the maximum number of cows that can be accommodated in each barn. The next n rows of each row of B digits represent the rank of the cow in the cattle. I'll take a walk! Really depressed, WA a good many times finally AC found themselves wrong because the re-composition after the subscript is starting from 0, changed to subscript starting from 1 AC
#include <stdio.h>#include<string.h>#include<algorithm>#include<iostream>#include<vector>#include<queue>#include<cmath>using namespacestd;#defineINF 0X3FFFFFFF#defineMAXN 1255intN, M;///N Cow m Cattle barnBOOLVIS[MAXN];intLIMT[MAXN];///represents the maximum amount that a barn can holdvector<vector<int> >G;vector<vector<int> > P;///used to save matching data.BOOLFind (intUintLintR) {     for(intI=l; i<=r; i++)///traverse the front K-side of U    {        intv = g[u][i-1]; if( !Vis[v]) {Vis[v]=true; if(P[v].size () <Limt[v])                {p[v].push_back (U); return true; }             for(intj=0; J<p[v].size (); J + +)            {                if(Find (P[v][j], L, R)) {p[v].erase (P[v].begin ()+j);                    P[v].push_back (U); return true; }            }        }    }    return false;}BOOLSolveintLintR)    {p.clear (); P.resize (M+Ten);  for(intI=1; i<=n; i++) {memset (Vis,false,sizeof(VIS)); if( !Find (i, L, R))return false; }    return true;}intMain () { while(SCANF ("%d%d", &n, &m)! =EOF)        {g.clear (); G.resize (n+Ten);  for(intI=1; i<=n; i++)        {             for(intj=1; j<=m; J + +)            {                intA; scanf ("%d", &a); G[i].push_back (a);///keep the rankings in each cow's eye            }        }         for(intI=1; i<=m; i++) scanf ("%d", &Limt[i]); intAns =INF;  for(intI=1; i<=m; i++)///Enumerate. We're only allowed to select the first I-Barn to the J-barn .        {             for(intJ=i; j<=m; J + +)            {                if(j-i+1>ans) Break; if(Solve (i, J)) ans= J-i +1; }} printf ("%d\n", ans); }    return 0;}

POJ 3189Steady Cow Assignment

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.