POJ 2584 T-Shirt Gumbo

T-Shirt Gumbo

Time Limit: 1000ms

Memory Limit: 65536KB

This problem will be judged on PKU. Original ID: 2584
64-bit integer IO format: %lld      Java class name: Main

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

South Central USA 2003

解题:多重匹配

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <vector>
 5 using namespace std;
 6 const int maxn = 30;
 7 int bound[maxn],shirt[maxn],n;
 8 vector<int>Link[maxn];
 9 bool e[maxn][maxn],used[maxn];
10 bool match(int u){
11     for(int i = 1; i <= 5; ++i){
12         if(e[u][i] && !used[i]){
13             used[i] = true;
14             if(Link[i].size() < bound[i]){
15                 Link[i].push_back(u);
16                 return true;
17             }
18             for(int j = Link[i].size()-1; j >= 0; --j){
19                 if(match(Link[i][j])){
20                     Link[i][j] = u;
21                     return true;
22                 }
23             }
24         }
25     }
26     return false;
27 }
28 char ans[2][50] = {"I‘d rather not wear a shirt anyway...\n","T-shirts rock!\n"};
29 int main(){
30     char str[20];
31     shirt[‘S‘-‘A‘] = 1;
32     shirt[‘M‘-‘A‘] = 2;
33     shirt[‘L‘-‘A‘] = 3;
34     shirt[‘X‘-‘A‘] = 4;
35     shirt[‘T‘-‘A‘] = 5;
36     while((~scanf("%s",str)) && strcmp(str,"ENDOFINPUT")){
37         scanf("%d",&n);
38         memset(e,false,sizeof e);
39         for(int i = 1; i <= n; ++i){
40             scanf("%s",str);
41             for(int j = shirt[str[0]-‘A‘]; j <= shirt[str[1]-‘A‘]; ++j)
42                 e[i][j] = true;
43         }
44         for(int i = 1; i <= 5; ++i)
45             scanf("%d",bound + i);
46         scanf("%s",str);
47         for(int i = 0; i < maxn; ++i) Link[i].clear();
48         int ret = 0;
49         for(int i = 1; i <= n; ++i){
50             memset(used,false,sizeof used);
51             if(match(i)) ++ret;
52         }
53         printf("%s",ans[ret == n]);
54     }
55     return 0;
56 }

时间: 2024-12-26 01:17:09

POJ 2584 T-Shirt Gumbo的相关文章

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

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 dis

poj 2584 T-Shirt Gumbo 网络流

题目链接 有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....代码能力太差了. 1 #include<bits/stdc++.h> 2 using n

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

题意: 有五种衣服尺码:S,M,L,X,T N个人,每个人都有一个可以穿的衣服尺码的范围,例:SX,意思是可以穿S,M,L,X的衣服. 给出五种尺码的衣服各有多少件. 如果可以满足所有人的要求,输出 T-shirts rock! 否则输出 I'd rather not wear a shirt anyway... 样例: 输入: 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 E

图论 500题——主要为hdu/poj/zoj

转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并查集======================================[HDU]1213   How Many Tables   基础并查集★1272   小希的迷宫   基础并查集★1325&&poj1308  Is It A Tree?   基础并查集★1856   More i

图论常用算法之一 POJ图论题集【转载】

POJ图论分类[转] 一个很不错的图论分类,非常感谢原版的作者!!!在这里分享给大家,爱好图论的ACMer不寂寞了... (很抱歉没有找到此题集整理的原创作者,感谢知情的朋友给个原创链接) POJ:http://poj.org/ 1062* 昂贵的聘礼 枚举等级限制+dijkstra 1087* A Plug for UNIX 2分匹配 1094 Sorting It All Out floyd 或 拓扑 1112* Team Them Up! 2分图染色+DP 1125 Stockbroker

POJ2584 T-Shirt Gumbo【二分图多重匹配】

题目链接: id=2584">http://poj.org/problem?id=2584 题目大意: 如今有5种型号(S.M.L.X.T)的衣服要发放给N个參赛队员.给出每一个參赛者所须要衣服型号的范围. 在这个范围内的型号參赛者都能接受.再给出这5种型号衣服各自的数量,那么问题来了:是否存在一种 分配方案使得全部參赛队员都可以拿到自己型号范围内的衣服. 思路: 二分图匹配是一个对一个的匹配,这里是一对多匹配.须要用二分图多重匹配的模型来做.详细就是把原 先匈牙利算法中的cy[MAXN]

POJ2584_T-Shirt Gumbo(二分图多重最大匹配/最大流)

解题报告 http://blog.csdn.net/juncoder/article/details/38239367 题目传送门 题意: X个參赛选手,每一个选手有衣服大小的范围,5种大小的队服,求能否使每一个选手都拿到符合自己大小范围的衣服. 思路: X人5种衣服,有的人选的衣服可能大小一样,这样就是二分图的多重最大匹配.源点到5种衣服的容量就是衣服的数量. #include <queue> #include <queue> #include <cstdio> #i

POJ - 3186 Treats for the Cows (区间DP)

题目链接:http://poj.org/problem?id=3186 题意:给定一组序列,取n次,每次可以取序列最前面的数或最后面的数,第n次出来就乘n,然后求和的最大值. 题解:用dp[i][j]表示i~j区间和的最大值,然后根据这个状态可以从删前和删后转移过来,推出状态转移方程: dp[i][j]=max(dp[i+1][j]+value[i]*k,dp[i][j-1]+value[j]*k) 1 #include <iostream> 2 #include <algorithm&

POJ 2533 - Longest Ordered Subsequence(最长上升子序列) 题解

此文为博主原创题解,转载时请通知博主,并把原文链接放在正文醒目位置. 题目链接:http://poj.org/problem?id=2533 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1, ai2, ..., aiK)