• 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

     
    解题:多重匹配
     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...
    ","T-shirts rock!
    "};
    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 }
    View Code
  • 相关阅读:
    导航属性
    提笔忘字
    JavaScript学习总结(一)——闭包、对象、函数
    CSS3新特性(阴影、动画、渐变)
    图片轮播(也可以通过点击下标播放对应的图片)
    CSS3与页面布局学习总结——多种页面布局
    多种居中方法
    二级菜单
    无间隙轮播图片
    模块和程序处理
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4854185.html
Copyright © 2020-2023  润新知