首页 > 其他分享 >poj 2584 T-Shirt Gumbo 二分匹配

poj 2584 T-Shirt Gumbo 二分匹配

时间:2023-04-26 17:33:34浏览次数:41  
标签:2584 return Shirt int will poj shirts line match


T-Shirt Gumbo


Time Limit: 1000MS

 

Memory Limit: 65536K

Total Submissions: 2935

 

Accepted: 1376


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


//二分匹配,把队员看成第一点集,衣服看成第二点集,学生接受衣服的范围和衣服都要预处理一下,之后套匈牙利模板,最大匹配若等于学生数,即能使所有人满意
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

const int N = 510;

int match[N];
bool use[N];
bool s[N][N];
int n, k;

bool dfs(int v)
{
    for(int i = 0; i < N; i++)
    {
        if(s[v][i] == true && use[i] == false)
        {
            use[i] = true;
            if(match[i] == -1 || dfs(match[i]))
            {
                match[i] = v;
                return true;
            }
        }
    }

    return false;
}

int hungary()
{
    int res = 0;
    memset(match, -1, sizeof match);
    for(int i = 0; i < n; i++)
    {
        memset(use, 0, sizeof use);
        if(dfs(i)) res++;
    }

    return res;
}

int ju(char a)
{
    if(a == 'S') return 1;
    else if(a == 'M') return 2;
    else if(a == 'L') return 3;
    else if(a == 'X') return 4;
    else return 5;
}

int main()
{
    char str[20];
    char a, b;
    int aa[N], bb[N], tmp[10] = {};


    while(scanf(" %s", str), strcmp(str, "ENDOFINPUT") != 0)
    {
        scanf("%d", &n);

        memset(s, 0, sizeof s);
        for(int i = 0; i < n; i++)
        {
            scanf(" %c%c", &a, &b);
            aa[i] = ju(a); //预处理队员可接受的衣服范围,转换为数字
            bb[i] = ju(b);
        }

        for(int i = 1; i <= 5; i++)
        {
            scanf("%d", tmp + i);
            tmp[i] += tmp[i-1]; //预处理衣服,把每一件衣服独立成一个点
        }
        scanf(" %s", str);
        for(int i = 0; i < n; i++)
        {
            for(int j = aa[i]; j <= bb[i]; j++)
            {
                for(int k = tmp[j-1] + 1; k <= tmp[j]; k++)
                    s[i][k] = true;
            }
        }

        if(hungary() == n) printf("T-shirts rock!\n");
        else printf("I'd rather not wear a shirt anyway...\n");
    }

    return 0;
}



标签:2584,return,Shirt,int,will,poj,shirts,line,match
From: https://blog.51cto.com/u_4158567/6228226

相关文章

  • POJ 3352 Road Construction 边双联通分量
    题目:http://poj.org/problem?id=3352题意:加上最少的边,使得改造后的图中去掉任意一条边后图依然连通,题中任意两个点之间不会有重边思路:删掉任意一条边图依然连通,意味着任意两点间有至少两条通路。对于边双连通分量内的任意两点,至少会有两条通路,所以求边双连通分量,缩点,求出度为1的点......
  • POJ - 3764 XOR&&dfs 01字典树
    Inanedge-weightedtree,thexor-lengthofapathpisdefinedasthexorsumoftheweightsofedgesonp:{xor}length§=\oplus{e\inp}w(e)⊕isthexoroperator.Wesayapaththexor-longestpathifithasthelargestxor-length.Givenanedge-weigh......
  • POJ - 3614 贪心
    Toavoidunsightlyburnswhiletanning,eachoftheC(1≤C≤2500)cowsmustcoverherhidewithsunscreenwhenthey’reatthebeach.CowihasaminimumandmaximumSPFrating(1≤minSPFi≤1,000;minSPFi≤maxSPFi≤1,000)thatwillwork.Ifthe......
  • POJ 1502 MPI Maelstrom(最短路)
    MPIMaelstromTimeLimit: 1000MS MemoryLimit: 10000KTotalSubmissions: 5476 Accepted: 3409DescriptionBIThasrecentlytakendeliveryoftheirnewsupercomputer,a32processorApolloOdysseydistributedsharedmemorymachinewithahierarchica......
  • POJ 2442 Sequence
    F- SequenceTimeLimit:6000MS     MemoryLimit:65536KB     64bitIOFormat:%I64d&%I64uSubmit Status Practice POJ2442DescriptionGivenmsequences,eachcontainsnnon-negativeinteger.Nowwemayselectonenumber......
  • POJ3984 迷宫问题(BFS 记忆路径)
    迷宫问题TimeLimit:1000MS     MemoryLimit:65536KB     64bitIOFormat:%I64d&%I64uSubmit Status Practice POJ3984SystemCrawler (2014-09-11)Description定义一个二维数组: intmaze[5][5]={0,1,0,0......
  • POJ 1789 Truck History
    TruckHistoryTimeLimit:2000MS     MemoryLimit:65536KB     64bitIOFormat:%I64d&%I64uSubmit Status Practice POJ1789DescriptionAdvancedCargoMovement,Ltd.usestrucksofdifferenttypes.Sometrucksareused......
  • POJ--3050 Hopscotch(暴搜)
    记录21:362023-4-16http://poj.org/problem?id=3050reference:《挑战程序设计竞赛(第2版)》第二章练习题索引p135DescriptionThecowsplaythechild'sgameofhopscotchinanon-traditionalway.Insteadofalinearsetofnumberedboxesintowhichtohop,thec......
  • kuangbin专题一 简单搜索 迷宫问题(POJ-3984)
    迷宫问题TimeLimit:1000MS MemoryLimit:65536KDescription定义一个二维数组:intmaze[5][5]={0,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0,};它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编......
  • kuangbin专题一 简单搜索 罐子(POJ-3414)
    PotsTimeLimit:1000MS MemoryLimit:65536KDescriptionYouaregiventwopots,havingthevolumeofAandBlitersrespectively.Thefollowingoperationscanbeperformed:FILL(i)fillthepoti(1≤i≤2)fromthetap;DROP(i)emptythep......