poj 2584 T-Shirt Gumbo (二分匹配)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 2571 | Accepted: 1202 |
Description
Input
A single data set has 4 components:
- Start line - A single line:
START Xwhere (1 <= X <= 20) is the number of contestants demanding shirts.
- Tolerance line - A single line containing X space-separated pairs of letters indicating the size tolerances of each contestant. Valid size letters are S - small, M - medium, L - large, X - extra large, T - extra extra large. Each letter pair will indicate the range of sizes that will satisfy a particular contestant. The pair will begin with the smallest size the contestant will accept and end with the largest. For example:
MXwould indicate a contestant that would accept a medium, large, or extra large T-shirt. If a contestant is very picky, both letters in the pair may be the same.
- Inventory line - A single line:
S M L X Tindicating the number of each size shirt in Boudreaux and Thibodeaux's inventory. These values will be between 0 and 20 inclusive.
- End line - A single line:
END
After the last data set, there will be a single line:
ENDOFINPUT
Output
T-shirts rock!
Otherwise, output:
I'd rather not wear a shirt anyway...
Sample Input
START 1
ST
0 0 1 0 0
END
START 2
SS TT
0 0 1 0 0
END
START 4
SM ML LX XT
0 1 1 1 0
END
ENDOFINPUT
Sample Output
T-shirts rock!
I'd rather not wear a shirt anyway...
I'd rather not wear a shirt anyway...
Source
//140K 0MS C++ 1519B 2014-06-09 08:53:58
/*
题意:
有x个人,没个人要穿的的衣服码数要在一个范围内,给出5种不同码的衣服的数量,问是否可以满足x个人的需求。 最大匹配:
构好图后直接最大匹配即可。构图的要知道是什么和什么匹配,要以人和衣服匹配,人数是固定的,衣服也是,
即是二分图的两个集合,匹配时每一件衣服作为一个点,而不是每一类衣服作为一个点。 */
#include<stdio.h>
#include<string.h>
int g[][];
int match[];
int vis[];
char r[]={"SMLXT"};
int x;
int judge(int i,char range[])
{
int lr,rr;
for(int j=;j<;j++){
if(range[]==r[j]) lr=j;
if(range[]==r[j]) rr=j;
}
if(i>=lr && i<=rr) return ;
return ;
}
int dfs(int u)
{
for(int i=;i<x;i++)
if(!vis[i] && g[u][i]){
vis[i]=;
if(match[i]==- || dfs(match[i])){
match[i]=u;
return ;
}
}
return ;
}
int hungary(int pos)
{
int ret=;
memset(match,-,sizeof(match));
for(int i=;i<=pos;i++){
memset(vis,,sizeof(vis));
ret+=dfs(i);
}
return ret;
}
int main(void)
{
char op[],stu[][];
int a[];
while(scanf("%s",op)!=EOF)
{
if(strcmp(op,"ENDOFINPUT")==) break;
scanf("%d",&x);
for(int i=;i<x;i++)
scanf("%s",&stu[i]);
for(int i=;i<;i++)
scanf("%d",&a[i]);
scanf("%s",op);
memset(g,,sizeof(g));
int pos=;
for(int i=;i<;i++){
while(a[i]--){
pos++;
for(int j=;j<x;j++)
if(judge(i,stu[j]))
g[pos][j]=;
}
}
if(hungary(pos)==x)
puts("T-shirts rock!");
else puts("I'd rather not wear a shirt anyway...");
}
return ;
}
poj 2584 T-Shirt Gumbo (二分匹配)的更多相关文章
- poj 2060 Taxi Cab Scheme (二分匹配)
Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5710 Accepted: 2393 D ...
- poj 1034 The dog task (二分匹配)
The dog task Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2559 Accepted: 1038 Sp ...
- TTTTTTTTTTTTTTTTT POJ 2226 草地覆木板 二分匹配 建图
Muddy Fields Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9754 Accepted: 3618 Desc ...
- TTTTTTTTTTTTTTTTTT POJ 2724 奶酪消毒机 二分匹配 建图 比较难想
Purifying Machine Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5004 Accepted: 1444 ...
- POJ 1466 大学谈恋爱 二分匹配变形 最大独立集
Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 11694 Accepted: 5230 D ...
- POJ 3020 Antenna Placement【二分匹配——最小路径覆盖】
链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- poj 1274 The Prefect Stall - 二分匹配
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22736 Accepted: 10144 Description Far ...
- poj 1274 The Perfect Stall (二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17768 Accepted: 810 ...
- POJ 2226 Muddy Fields(二分匹配 巧妙的建图)
Description Rain has pummeled the cows' field, a rectangular grid of R rows and C columns (1 <= R ...
随机推荐
- [hdu 2686]Matrix
网上说这道题的题解是费用流 我粗粗看了一下数据范围,觉得出题者似乎是让我们用 “大(d)屁(p)” 的样子,为了尊重出题人,我还是写一写吧喵~ 首先,一条回路可以看做是两条路齐头并进,这是 大屁 和 ...
- c语言多线程队列读写
最近用c语言写了个简单的队列服务,记录一下,文件结构为 main.c queue.c queue.h,代码如下: 主函数 #define NUM_THREADS 200 #include <st ...
- HTTP POST GET详解
get /shang/a1.php http/1.1 host: localhost POST /shang/a1.php HTTP/1.1 Hos ...
- bootstrap初接触
Bootstrap 是最受欢迎的 HTML.CSS 和 JS 框架.(主要是结合HTML5 CSS3的样式, 基于jquery+Bootstrap 自带 12 种 jQuery 插件,扩展了功能,可以 ...
- 一、Spring——IoC
IOC概述 Spring中IOC的概念,控制反转概念其实包含两个层面的意思,"控制"是接口实现类的选择控制权:而"反转"是指这种选择控制权从调用者转移到外部第三 ...
- ruby&mongo_mapper
mongo_mapper&ruby Mongomapper 用户mongo数据库配置,以及其提供了很多mongo的方法,可以很好地用来 对mongo相关封装和操作. 环境准备:gem inst ...
- zxing 一维码部分深入分析与实际应用,识别卡片数量,Android数卡器
打算修改zxing 源码应用到其它方面,所以最近花了点时间阅读其源码,无意中找到这篇博客,条码扫描二维码扫描——ZXing android 简化源码分析 对过程的分析还是可以参考的.原作者给出的一个基 ...
- day6_1
一.加密模块 1.hashlib >>> data=hashlib.md5() >>> data.update(b'hello') >>> pri ...
- 项目管理软件之易度1.5,禅道2.0,redmine1.2(附redmine1.2的安装)
http://www.cnblogs.com/ljzforever/archive/2011/06/29/2093786.html 公司最近准备分出一套人马去客户那里做驻场研发,这就涉及到代码库的统一 ...
- 从Windows 2012标准版升级到数据中心版,标准评价版本升级到标准体验版本并激活
对于Windows 7.Windows 8操作系统,可以在图形界面中通过输入序列号,从低版本直接升级到高的版本,例如从Windows 7家庭版升级到专业版或旗舰版.而对于Windows Server ...