O - Steady Cow Assignment - POJ 3189(多重匹配+枚举)
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int MAXN = ;
const int MAXM = ; int G[MAXN][MAXM], N, M;
int cows[MAXM];///牛棚最多可以安放的牛的数量
bool used[MAXM];
struct Link{int link[MAXN], len;}Ly[MAXM]; bool Find(int i, int L, int R)
{
for(int j=; j<=M; j++)
{
if( G[i][j]>=L && G[i][j]<=R && !used[j] )
{
used[j] = true; if( Ly[j].len < cows[j] )
{
Ly[j].link[ Ly[j].len++ ] = i;
return true;
}
for(int k=; k<Ly[j].len; k++)
{
if( Find( Ly[j].link[k], L, R ) == true )
{
Ly[j].link[k] = i;
return true;
}
}
}
} return false;
}
bool XYL(int L, int R)
{
memset(Ly, false, sizeof(Ly)); for(int i=; i<=N; i++)
{
memset(used, false, sizeof(used));
if( Find(i, L, R) == false )
return false;
} return true;
} int main()
{
while(scanf("%d%d", &N, &M) != EOF)
{
int i, j, L=, R=M, Mid, ans, v; for(i=; i<=N; i++)
for(j=; j<=M; j++)
{
scanf("%d", &v);
G[i][v] = j;
} for(i=; i<=M; i++)
scanf("%d", &cows[i]); while(L <= R)
{
Mid = (L+R) >> ; for(i=; i<=M; i++)
{
if( XYL(i, i+Mid) == true )
break;
} if(i <= M)
R = Mid-, ans = Mid;
else
L = Mid+;
} printf("%d\n", ans+);
} return ;
}
O - Steady Cow Assignment - POJ 3189(多重匹配+枚举)的更多相关文章
- Steady Cow Assignment POJ - 3189 (最大流+匹配)
Farmer John's N (1 <= N <= 1000) cows each reside in one of B (1 <= B <= 20) barns which ...
- POJ 3189——Steady Cow Assignment——————【多重匹配、二分枚举区间长度】
Steady Cow Assignment Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
- Poj 3189 Steady Cow Assignment (多重匹配)
题目链接: Poj 3189 Steady Cow Assignment 题目描述: 有n头奶牛,m个棚,每个奶牛对每个棚都有一个喜爱程度.当然啦,棚子也是有脾气的,并不是奶牛想住进来就住进来,超出棚 ...
- POJ3189:Steady Cow Assignment(二分+二分图多重匹配)
Steady Cow Assignment Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7482 Accepted: ...
- POJ3189 Steady Cow Assignment —— 二分图多重匹配/最大流 + 二分
题目链接:https://vjudge.net/problem/POJ-3189 Steady Cow Assignment Time Limit: 1000MS Memory Limit: 65 ...
- POJ 2289 Jamie's Contact Groups & POJ3189 Steady Cow Assignment
这两道题目都是多重二分匹配+枚举的做法,或者可以用网络流,实际上二分匹配也就实质是网络流,通过枚举区间,然后建立相应的图,判断该区间是否符合要求,并进一步缩小范围,直到求出解.不同之处在对是否满足条件 ...
- POJ3189 Steady Cow Assignment
Steady Cow Assignment Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6817 Accepted: ...
- POJ 3189 Steady Cow Assignment 【二分】+【多重匹配】
<题目链接> 题目大意: 有n头牛,m个牛棚,每个牛棚都有一定的容量(就是最多能装多少只牛),然后每只牛对每个牛棚的喜好度不同(就是所有牛圈在每个牛心中都有一个排名),然后要求所有的牛都进 ...
- POJ 3189 Steady Cow Assignment
题意:每个奶牛对所有的牛棚有个排名(根据喜欢程度排的),每个牛棚能够入住的牛的数量有个上限,重新给牛分配牛棚,使牛棚在牛心中的排名差(所有牛中最大排名和最小排名之差)最小. 题目输入: 首先是两个 ...
随机推荐
- Linux access
1.access函数 功能描述:检查调用进程是否可以对指定的文件执行某种操作. 用法: #include <unistd.h> #include <fcntl.h>int ac ...
- POJ 1986(LCA and RMQ)
题意:给定一棵树,求任意两点之间的距离. 思路:由于树的特殊性,所以任意两点之间的路径是唯一的.u到v的距离等于dis(u) + dis(v) - 2 * dis(lca(u, v)); 其中dis( ...
- IDisposable接口详解
转载:http://www.cnblogs.com/davyli/archive/2010/09/13/1825042.html 正确实现 IDisposable .NET中用于释放对象资源的接口是I ...
- Android开发手记(24) Log的使用及颜色的更改
在程序开发过程中,LOG是广泛使用的用来记录程序执行过程的机制,它既可以用于程序调试,也可以用于产品运营中的事件记录.在Android系统中,提供了简单.便利的LOG机制,开发人员可以方便地使用.本文 ...
- 推送:腾迅信鸽 VS Bmob
最近几天了解市场上主流的推送SDK. 腾迅信鸽 所需SDK,去官网自行下载.去下载 完整的清单文件如下: <?xml version="1.0" encoding=" ...
- Swift - 32 - 函数类型
//: Playground - noun: a place where people can play import UIKit func add(a:Int, b:Int) -> Int { ...
- POJ2566-Bound Found (尺取法)
POJ2566-Bound Found 题目大意:给出一段长度为n的数列,数列中的元素有正有负,求一段连续的区间,使得该区间的和的绝对值最接近给定的值 尺取法一般适用于对一段连续的区间的和进行处理的情 ...
- Spring mvc 中有关 Shiro 1.2.3 配置问题
Spring 版本:3.2.x, 4.0.x [问题说明] 首先介绍下配置出错情况: (1)项目中,Spring3 and Spring4 的 applicationContext.xml aop ...
- Adb shell 常用命令
1. 查看IP adb shell netcfg 2. 查看挂载设备 adb devices 3. 将本地端口转发至手机端口 adb forward tcp: tcp: // PC上所有6100端口通 ...
- [Apio2014]回文串
http://www.lydsy.com:808/JudgeOnline/problem.php?id=3676 这是一道回文树裸题,具体如何建图见http://blog.csdn.net/u0133 ...