博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 3189 Steady Cow Assignment 二分图多重匹配+二分
阅读量:3904 次
发布时间:2019-05-23

本文共 1932 字,大约阅读时间需要 6 分钟。

题目:

Farmer John's N (1 <= N <= 1000) cows each reside in one of B (1 <= B <= 20) barns which, of course, have limited capacity. Some cows really like their current barn, and some are not so happy.

FJ would like to rearrange the cows such that the cows are as equally happy as possible, even if that means all the cows hate their assigned barn.
Each cow gives FJ the order in which she prefers the barns. A cow's happiness with a particular assignment is her ranking of her barn. Your job is to find an assignment of cows to barns such that no barn's capacity is exceeded and the size of the range (i.e., one more than the positive difference between the the highest-ranked barn chosen and that lowest-ranked barn chosen) of barn rankings the cows give their assigned barns is as small as possible.

Input

Line 1: Two space-separated integers, N and B

Lines 2..N+1: Each line contains B space-separated integers which are exactly 1..B sorted into some order. The first integer on line i+1 is the number of the cow i's top-choice barn, the second integer on that line is the number of the i'th cow's second-choice barn, and so on.
Line N+2: B space-separated integers, respectively the capacity of the first barn, then the capacity of the second, and so on. The sum of these numbers is guaranteed to be at least N.

Output

Line 1: One integer, the size of the minumum range of barn rankings the cows give their assigned barns, including the endpoints.

Sample Input

6 41 2 3 42 3 1 44 2 3 13 1 2 41 3 4 21 4 2 32 1 3 2

Sample Output

2

思路:

建好图之后,通过二分的方式来确定区间,然后判定是否符合条件。

代码如下:

#include 
#include
#include
#include
using namespace std;const int maxn=1e3+5;int a[maxn][maxn];int match[maxn][maxn];int vis[maxn];int num[maxn];int lim[maxn];int n,b;bool Find(int x,int l,int r){ for (int i=1;i<=b;i++) { if(!vis[i]&&a[x][i]>=l&&a[x][i]<=r) { vis[i]=1; if(num[i]

 

转载地址:http://czoen.baihongyu.com/

你可能感兴趣的文章
哈佛大学凌晨4点半的景象--哈佛图书馆的二十条训言
查看>>
闲话机器人领域的国际会议
查看>>
Outlook2010到处通讯录
查看>>
Gmail导入通讯录
查看>>
小米笔记本安装Win 10历程
查看>>
【转】SLAM 论文阅读和分类整理
查看>>
【转】Ubuntu 16.04 重置密码(忘记密码)
查看>>
【转】信息奥赛一本通1185:单词排序(OJ题目描述有问题)
查看>>
【转】在EXCEL表格中如何用厘米毫米来设置行高列宽?
查看>>
开源spider
查看>>
HttpUnit: 一种在 WebSphere Studio 中测试 Web 应用程序的改进方式
查看>>
Python Self
查看>>
webclient
查看>>
从百度MP3搜索结果中提取歌曲列表
查看>>
python模块之HTMLParser
查看>>
模拟IE(FireFox)的Spider技术介绍
查看>>
去除文本中的空行的bash命令
查看>>
Sift Applcation
查看>>
我网易的blog
查看>>
linux下启动mysql
查看>>