poj 2584 T-Shirt Gumbo

Boudreaux和Thibodeaux作为志愿者,面临分配编程竞赛T恤的挑战,需根据参赛者的尺寸偏好和库存数量,确保每人都能获得合适的T恤。本文详细介绍了输入格式、算法解决方案及代码实现。

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;
}
混合动力汽车(HEV)模型的Simscape模型(Matlab代码、Simulink仿真实现)内容概要:本文档介绍了一个混合动力汽车(HEV)的Simscape模型,该模型通过Matlab代码和Simulink仿真工具实现,旨在对混合动力汽车的动力系统进行建模与仿真分析。模型涵盖了发动机、电机、电池、传动系统等关键部件,能够模拟车辆在不同工况下的能量流动与控制策略,适用于动力系统设计、能耗优化及控制算法验证等研究方向。文档还提及该资源属于一个涵盖多个科研领域的MATLAB仿真资源包,涉及电力系统、机器学习、路径规划、信号处理等多个技术方向,配套提供网盘下载链接,便于用户获取完整资源。; 适合人群:具备Matlab/Simulink使用基础的高校研究生、科研人员及从事新能源汽车系统仿真的工程技术人员。; 使用场景及目标:①开展混合动力汽车能量管理策略的研究与仿真验证;②学习基于Simscape的物理系统建模方法;③作为教学案例用于车辆工程或自动化相关课程的实践环节;④与其他优化算法(如智能优化、强化学习)结合,实现控制策略的优化设计。; 阅读建议:建议使用者先熟悉Matlab/Simulink及Simscape基础操作,结合文档中的模型结构逐步理解各模块功能,可在此基础上修改参数或替换控制算法以满足具体研究需求,同时推荐访问提供的网盘链接获取完整代码与示例文件以便深入学习与调试。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值