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

Description

Boudreaux and Thibodeaux are student volunteers for this year's ACM South Central Region's programming contest. One of their duties is to distribute the contest T-shirts to arriving teams. The T-shirts had to be ordered in advance using an educated guess as to how many shirts of each size should be needed. Now it falls to Boudreaux and Thibodeaux to determine if they can hand out T-shirts to all the contestants in a way that makes everyone happy.

Input

Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets.

A single data set has 4 components: 

  1. Start line - A single line: 
    START X

    where (1 <= X <= 20) is the number of contestants demanding shirts.

  2. 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: 
    MX 

    would 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.

  3. Inventory line - A single line: 
    S M L X T 

    indicating the number of each size shirt in Boudreaux and Thibodeaux's inventory. These values will be between 0 and 20 inclusive.

  4. End line - A single line: 
    END

After the last data set, there will be a single line: 
ENDOFINPUT

Output

For each data set, there will be exactly one line of output. This line will reflect the attitude of the contestants after the T-shirts are distributed. If all the contestants were satisfied, 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 (二分匹配)的更多相关文章

  1. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

  2. poj 1034 The dog task (二分匹配)

    The dog task Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2559   Accepted: 1038   Sp ...

  3. TTTTTTTTTTTTTTTTT POJ 2226 草地覆木板 二分匹配 建图

    Muddy Fields Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9754   Accepted: 3618 Desc ...

  4. TTTTTTTTTTTTTTTTTT POJ 2724 奶酪消毒机 二分匹配 建图 比较难想

    Purifying Machine Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5004   Accepted: 1444 ...

  5. POJ 1466 大学谈恋爱 二分匹配变形 最大独立集

    Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 11694   Accepted: 5230 D ...

  6. POJ 3020 Antenna Placement【二分匹配——最小路径覆盖】

    链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  7. poj 1274 The Prefect Stall - 二分匹配

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22736   Accepted: 10144 Description Far ...

  8. poj 1274 The Perfect Stall (二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17768   Accepted: 810 ...

  9. POJ 2226 Muddy Fields(二分匹配 巧妙的建图)

    Description Rain has pummeled the cows' field, a rectangular grid of R rows and C columns (1 <= R ...

随机推荐

  1. 如何使Android应用开机时自动启动

    先记下来,主要是继承BroadcastReceiver实现.还有开机自动启动service的,好像是继承 IntentReceiver,不知道有什么不一样,有时间试试. 一: 简单 Android也有 ...

  2. nginx配置rewrite

    1. uri  和 url读取区别 区别就是URI定义资源,而URL不单定义这个资源,还定义了如何找到这个资源. 比如说,一个服务器上,到一个文件夹/网页的绝对地址(absolute path)就是U ...

  3. Difference between applicationContext.xml and spring-servlet.xml in Spring Framework

    Question: Are applicationContext.xml and spring-servlet.xml related anyhow in Spring Framework? Will ...

  4. windows下用一台机器配置分布式redis(主从服务器)

    目录1.Replication的工作原理2.如何配置Redis主从复制 1.Replication的工作原理在Slave启动并连接到Master之后,它将主动发送一条SYNC命令.此后Master将启 ...

  5. 关于http协议详解

    Author :Jeffrey 引言 HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990年提出,经过几年的使用与发展,得到不断地完善和扩展.目前 ...

  6. NPOI生成单元格(列)下拉框

    客户提出能否将导入模板中,课程一列添加下拉框方便选择,不用手输入,以减少输入错误的可能性.于是在网上找了点代码,稍加整理后,形成了以下方案,代码部分: 一:生成课程列表,并放置在excel的单独she ...

  7. 洛谷P3366 【模板】最小生成树

    P3366 [模板]最小生成树 319通过 791提交 题目提供者HansBug 标签 难度普及- 提交  讨论  题解 最新讨论 里面没有要输出orz的测试点 如果你用Prim写了半天都是W- 题目 ...

  8. openldap主机访问控制(基于用户组)

    建立组织单元 cat << _EOF_ | ldapadd -x -W -H ldaps://master.local -D cn=manager,dc=suntv,dc=tv dn: o ...

  9. Qlikview 处理增量数据的脚本

    一般设计Qlikview报表的时候需要些2个脚本文件,一个针对Qlikview的Server job 导出数据到qvd数据文具. 另一个用户访问的Qlikview的脚本是直接展示qvd文件的数据. 事 ...

  10. 用Python给你的博客加上水印

    之前写的博客里面用到的图片都没有加水印,今天才在别的网站上发现自己的博客居然一个字不动的出现在了别人的文章里,而且还不标注出处,简直醉了. 其实博客这种东西讲真我是很愿意让别人看得,因为自己写的也比较 ...