poj 2584 T-Shirt Gumbo

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:
Start line - A single line:
START X

where (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:
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.
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.
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...

Key To Problem

题意:给定每个选手可以穿的衣服型号以及每种衣服型号有多少件,求是否可以使每位选手都能穿合适的衣服。
题解:可以将每种型号的每件衣服都单列为一种衣服,如果一位选手可以穿上这种衣服,那么久将该选手与这种衣服连边,之后用匈牙利算法求二分图即可。
//做完题之后去查题解看到有一种叫做二分图多重匹配的东西,之后发现这道题是裸题啊!果然本弱很弱做的题也很弱!

Code

#include <map>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 2005
using namespace std;
struct ss
{
    int next,to;
};
ss Edge[N*N];
struct node
{
    int from,to;
};
node E[N];
map<char,int>V;
int n,tot,m;
int head[N];
char s[N];
int f[N];
int a[N];
bool used[N];

void init()
{
    tot=0;
    memset(head,0,sizeof(head));
    memset(a,0,sizeof(a));
}

void add(int x,int y)
{
    Edge[++tot].next=head[x];
    Edge[tot].to=y;
    head[x]=tot;
}

bool dfs(int u)
{
    for(int i=head[u];i;i=Edge[i].next)
    {
        int to=Edge[i].to;
        if(!used[to])
        {
            used[to]=true;
            if(f[to]==-1||dfs(f[to]))
            {
                f[to]=u;
                return true;
            }
        }
    }
    return false;
}

int hungary()
{
    int cnt=0;
    memset(f,-1,sizeof(f));
    for(int i=1;i<=n;i++)
    {
        memset(used,0,sizeof(used));
        if(dfs(i))cnt++;
    }
    return cnt;
}

int main()
{
    V['S']=1,V['M']=2,V['L']=3,V['X']=4,V['T']=5;
    while(scanf("%s",s)&&strcmp(s,"ENDOFINPUT")!=0)
    {
        init();
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%s",s+1);
            E[i].from=V[s[1]],E[i].to=V[s[2]];
        }
        for(int i=1;i<=5;i++)
        {
            int x;
            scanf("%d",&x);
            while(x)
            {
                m++;
                for(int j=1;j<=n;j++)
                    if(E[j].from<=i&&E[j].to>=i)add(j,m);
                x--;
            }
        }
        if(hungary()==n)puts("T-shirts rock!");
        else puts("I'd rather not wear a shirt anyway...");
        scanf("%s",s);
        memset(s,0,sizeof(s));
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值