Topic Links:
Poj 3189 Steady Cow Assignment
Title Description:
There are n cows, m sheds, and each cow has a degree of affection for each shed. Of course, the shed is also a temper, not the cows want to live in and live in, beyond the maximum capacity of the shed, the shed is rejected. Now to make a home for each cow, this baby is a fair and impartial human, so to find a cow love degree of the smallest scheme (although this may be generally low, because the absolute fairness does not mean reasonable AH), ask the extent of the degree of love to the minimum is how big?
Problem Solving Ideas:
Each shed does not live on a cow, so it is a multiple match. Match the time of the two-point enumeration of the degree of affection of the interval size, according to the interval size to enumerate the beginning and end of the interval, and then run multiple matches to determine whether it is legal. Note that the interval size is not the difference between the maximum favorite degree and the minimum love degree. And, uh, when the data is read in, Maps[i][j] is not the i_th cow's favorite value for j_th shed, but the i_th cow's love for Maps[i][j] Sheds is J.
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5 using namespacestd;6 7 Const intMAXN =1010;8 intmaps[maxn][ A], vis[ A], used[ A][MAXN];9 intlink[ A], limit[ A], N, M, S, E, mid;Ten BOOLFind (intu) One { A for(intI=1; i<=m; i++) -{//multiple matches - if(!vis[i] && maps[u][i]<e && s<=Maps[u][i]) the { -Vis[i] =1; - if(Link[i] <Limit[i]) -{//I shed is not full +Used[i][link[i] + +] =u; - return true; + } A for(intj=0; j<limit[i]; J + +)//I'm full, looking for an augmented road at if(Find (Used[i][j])) - { -USED[I][J] =u; - return true; - } - } in } - return false; to } + BOOLhungry () - { the for(s=1; s<=m+1-mid; s++) *{//enumerating the beginning and end of an interval $ intAns =0;Panax NotoginsengE = s +mid; -memset (Link,0,sizeof(link)); the for(intI=1; i<=n; i++) + { Amemset (Vis,0,sizeof(Vis)); the if(Find (i)) +Ans + +; - } $ if(ans = =N) $ return true; - } - return false; the } - intMain ()Wuyi { the while(SCANF ("%d%d", &n, &m)! =EOF) - { Wu for(intI=1; i<=n; i++) - for(intj=1; j<=m; J + +) About { $scanf ("%d", &mid); -Maps[i][mid] =J; - } - for(intI=1; i<=m; i++) Ascanf ("%d", &limit[i]); + intleft =1, right = m, ans =0; the while(left<=Right ) -{//Two-Part enumeration interval $Mid = (right+left)/2; the if(Hungry ()) the { theAns =mid; theright = mid-1; - } in Else theLeft = mid +1; the } Aboutprintf ("%d\n", ans); the } the return 0; the}
Poj 3189 Steady Cow Assignment (multiple matches)