题目链接

有5种T-shirt, n个人, 每个人可以接受某些种T-shirt, 每种T-shirt的数量已知, 问每个人能否都穿上自己能接受的T-shirt。

源点向每种T-shirt连边, 权值为个数。 将人拆成两个点u和u', T-shirt向u连边, 权值为1, u向u'连边, 权值为1, u'向汇点连边, 权值为inf。 跑一遍最大流, 看结果是否等于n就可以了。

很简单的题写了好久orz....代码能力太差了。

 #include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
const int inf = ;
const int maxn = 1e4+;
int head[maxn*], s, t, num, q[maxn*], dis[maxn];
struct node
{
int to, nextt, c;
}e[maxn*];
void init() {
mem1(head);
num = ;
}
void add(int u, int v, int c) {
e[num].to = v; e[num].nextt = head[u]; e[num].c = c; head[u] = num++;
e[num].to = u; e[num].nextt = head[v]; e[num].c = ; head[v] = num++;
}
int bfs() {
int u, v, st = , ed = ;
mem(dis);
dis[s] = ;
q[ed++] = s;
while(st<ed) {
u = q[st++];
for(int i = head[u]; ~i; i = e[i].nextt) {
v = e[i].to;
if(e[i].c&&!dis[v]) {
dis[v] = dis[u]+;
if(v == t)
return ;
q[ed++] = v;
}
}
}
return ;
}
int dfs(int u, int limit) {
if(u == t)
return limit;
int cost = ;
for(int i = head[u]; ~i; i = e[i].nextt) {
int v = e[i].to;
if(e[i].c&&dis[u] == dis[v]-) {
int tmp = dfs(v, min(limit-cost, e[i].c));
if(tmp>) {
e[i].c -= tmp;
e[i^].c += tmp;
cost += tmp;
if(cost == limit)
break;
} else {
dis[v] = -;
}
}
}
return cost;
}
int dinic() {
int ans = ;
while(bfs()) {
ans += dfs(s, inf);
}
return ans;
}
map <char, int> m;
int val[];
char c[][];
int main()
{
m['S'] = , m['M'] = , m['L'] = , m['X'] = , m['T'] = ;
string str;
int n;
while(cin>>str) {
init();
if(str == "ENDOFINPUT")
break;
scanf("%d", &n);
s = , t = *n++;
for(int i = ; i<=n; i++) {
scanf("%s", c[i]);
}
for(int i = ; i<=; i++) {
scanf("%d", &val[i]);
}
for(int i = ; i<=; i++) {
add(s, i, val[i]);
}
for(int i = ; i<=n; i++) {
if(c[i][] == c[i][]) {
add(m[c[i][]], i+, );
} else {
for(int j = m[c[i][]]; j<=m[c[i][]]; j++) {
add(j, i+, );
}
}
}
for(int i = ; i<=n; i++) {
add(i+, i++n, );
add(i++n, t, inf);
}
cin>>str;
int ans = dinic();
if(ans == n) {
cout<<"T-shirts rock!"<<endl;
} else {
cout<<"I'd rather not wear a shirt anyway..."<<endl;
}
}
}

poj 2584 T-Shirt Gumbo 网络流的更多相关文章

  1. POJ 2135 Farm Tour (网络流,最小费用最大流)

    POJ 2135 Farm Tour (网络流,最小费用最大流) Description When FJ's friends visit him on the farm, he likes to sh ...

  2. POJ 2516 Minimum Cost (网络流,最小费用流)

    POJ 2516 Minimum Cost (网络流,最小费用流) Description Dearboy, a goods victualer, now comes to a big problem ...

  3. POJ 2584 T-Shirt Gumbo 二分图的多重匹配

    题目链接:http://poj.org/problem?id=2584 题目大意:有SMLXT五种T恤型号,有N个人,每个人有一个可选的型号区间,你现在要发给N个人每人一条他可以选择的型号的T恤,问能 ...

  4. poj 2584 T-Shirt Gumbo (二分匹配)

    T-Shirt Gumbo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2571   Accepted: 1202 Des ...

  5. POJ 2584 T-Shirt Gumbo

    T-Shirt Gumbo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3689   Accepted: 1755 Des ...

  6. POJ 2584 T-Shirt Gumbo (二分图多重最大匹配)

    题意 现在要将5种型号的衣服分发给n个参赛者,然后给出每个参赛者所需要的衣服的尺码的大小范围,在该尺码范围内的衣服该选手可以接受,再给出这5种型号衣服各自的数量,问是否存在一种分配方案使得每个选手都能 ...

  7. POJ 2584 T-Shirt Gumbo(二分图最大匹配)

    题意: 有五种衣服尺码:S,M,L,X,T N个人,每个人都有一个可以穿的衣服尺码的范围,例:SX,意思是可以穿S,M,L,X的衣服. 给出五种尺码的衣服各有多少件. 如果可以满足所有人的要求,输出 ...

  8. [题解]poj 1274 The Perfect Stall(网络流)

    二分匹配传送门[here] 原题传送门[here] 题意大概说一下,就是有N头牛和M个牛棚,每头牛愿意住在一些牛棚,求最大能够满足多少头牛的要求. 很明显就是一道裸裸的二分图最大匹配,但是为了练练网络 ...

  9. poj 1274 The Perfect Stal - 网络流

    二分匹配传送门[here] 原题传送门[here] 题意大概说一下,就是有N头牛和M个牛棚,每头牛愿意住在一些牛棚,求最大能够满足多少头牛的要求. 很明显就是一道裸裸的二分图最大匹配,但是为了练练网络 ...

随机推荐

  1. jQuery源码笔记——三

    将类数组对象转化为数组对象 javascript中有许多类数组对象,比如HTMLCollection,NodeList,arguments.她们的特点是和数组一样有length属性,并且有0,1,2这 ...

  2. html5滑动手势

    <div id="divMove" style="height: 100px;"></div> <div id="sli ...

  3. 查询EBS在线用户SQL(R12)

    SELECT U.USER_NAME, APP.APPLICATION_SHORT_NAME, FAT.APPLICATION_NAME, FR.RESPONSIBILITY_KEY, FRT.RES ...

  4. mongodb 备份与恢复

    备份 mongodump -d dbname -o backup 例如 mongodump -d student -o backup 恢复 mongorestore -d dbname -o back ...

  5. 内存管理之二——Cocos2d-x学习历程(六)

    1.工厂方法 工厂方法是程序设计中一个经典的设计模式,指的是基类中只定义创建对象的接口,将实际的实现推迟到子类中. CCObject* factoryMethod() { CCObject* ret ...

  6. python two-dimensional array assignment initialize

    #if you want to initialize a 9*9 two-dimensional array [([""]*9) for i in range(9)] #cauti ...

  7. http request parameter

    http request parameter add htmlspecialchars host?vendor_id=1000000&q=Some%20children%20wish%20to ...

  8. [置顶] js 控制文章中字体的大小,mootools实现

    文中字体要12.14.16号中选择: <span class="zh">字号:<b class="change-font">12< ...

  9. Android minHeight/Width,maxHeight/Width

    在layout文件中,设置IamgeView的最大(最小)高度(宽度)时,需要同时设置android:adjustViewBounds="true",这样设置才会生效.在代码中设置 ...

  10. js实现表格

    主要方法如下,然后今天学到了js的几个函数知识点. 1.eval()函数: 定义和用法eval() 函数可计算某个字符串,并执行其中的的 JavaScript 代码. 语法eval(string) 其 ...