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

     1 //140K    0MS    C++    1519B    2014-06-09 08:53:58
     2 /*
     3     题意:
     4         有x个人,没个人要穿的的衣服码数要在一个范围内,给出5种不同码的衣服的数量,问是否可以满足x个人的需求。 
     5     
     6     最大匹配:
     7         构好图后直接最大匹配即可。构图的要知道是什么和什么匹配,要以人和衣服匹配,人数是固定的,衣服也是,
     8     即是二分图的两个集合,匹配时每一件衣服作为一个点,而不是每一类衣服作为一个点。 
     9    
    10 */ 
    11 #include<stdio.h>
    12 #include<string.h>
    13 int g[105][25];
    14 int match[25];
    15 int vis[25];
    16 char r[6]={"SMLXT"};
    17 int x;
    18 int judge(int i,char range[])
    19 {
    20     int lr,rr;
    21     for(int j=0;j<5;j++){
    22         if(range[0]==r[j]) lr=j;
    23         if(range[1]==r[j]) rr=j;
    24     }
    25     if(i>=lr && i<=rr) return 1;
    26     return 0;
    27 }
    28 int dfs(int u)
    29 {
    30     for(int i=0;i<x;i++)
    31         if(!vis[i] && g[u][i]){
    32             vis[i]=1;
    33             if(match[i]==-1 || dfs(match[i])){
    34                 match[i]=u;
    35                 return 1;
    36             }
    37         }
    38     return 0;
    39 }
    40 int hungary(int pos)
    41 {
    42     int ret=0;
    43     memset(match,-1,sizeof(match));
    44     for(int i=1;i<=pos;i++){
    45         memset(vis,0,sizeof(vis));
    46         ret+=dfs(i);
    47     }
    48     return ret;
    49 }
    50 int main(void)
    51 {
    52     char op[20],stu[25][5];
    53     int a[10];
    54     while(scanf("%s",op)!=EOF)
    55     {
    56         if(strcmp(op,"ENDOFINPUT")==0) break;
    57         scanf("%d",&x);
    58         for(int i=0;i<x;i++)
    59             scanf("%s",&stu[i]);
    60         for(int i=0;i<5;i++)
    61             scanf("%d",&a[i]);
    62         scanf("%s",op);
    63         memset(g,0,sizeof(g));
    64         int pos=0;
    65         for(int i=0;i<5;i++){
    66             while(a[i]--){
    67                 pos++;
    68                 for(int j=0;j<x;j++)
    69                     if(judge(i,stu[j]))
    70                         g[pos][j]=1; 
    71             }
    72         }
    73         if(hungary(pos)==x)
    74             puts("T-shirts rock!");
    75         else puts("I'd rather not wear a shirt anyway...");
    76     }
    77     return 0;
    78 }
  • 相关阅读:
    Java变量以及内存分配
    在ORACLE存储过程中创建临时表
    CREATE OR REPLACE FUNCTION
    DECLARE
    CURSOR
    STM32WB SRAM2
    git版本控制
    STM32WB HSE校准
    STM32 HSE模式配(旁路模式、非旁路模式)
    STM32WB 信息块之OTP
  • 原文地址:https://www.cnblogs.com/GO-NO-1/p/3777193.html
Copyright © 2020-2023  润新知