zoukankan      html  css  js  c++  java
  • POJ 2584 T-Shirt Gumbo

    T-Shirt Gumbo
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 3689   Accepted: 1755

    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<cstring>
    using namespace std;
    const int M = 25;
    struct node{
        int s,e;
    }c[M];
    //S M L X T
    int g[M][M],v[M][M],vis[M],n,m,cnt[M],b[10];
    string a[M];
    int fx(char s1){
        if(s1 == 'S') return 0;
        else if(s1 == 'M') return 1;
        else if(s1 == 'L') return 2;
        else if(s1 == 'X') return 3;
        else if(s1 == 'T') return 4;
    }
    void fu(){
        for(int i=0;i<n;i++){
            c[i].s = fx(a[i][0]); c[i].e = fx(a[i][1]);
            //cout<<c[i].s<<" "<<c[i].e<<endl;
            for(int j=c[i].s;j<=c[i].e;j++){
                g[i][j] = 1;
            }
        }
    }
    bool dfs(int u){
        for(int i=0;i<5;i++){
            if(!vis[i]&&g[u][i]){
                vis[i] = 1;
                if(cnt[i]<b[i]){
                    v[i][cnt[i]++] = u;
                    return 1;
                }
                    for(int j=0;j<cnt[i];j++)
                        if(dfs(v[i][j])){
                            v[i][j] = u;
                            return 1;
                        }
            }
        }
        return 0;
    }
    int main(){
        string s,s4;
        while(1){
            memset(g,0,sizeof(g));
            memset(v,0,sizeof(v));
            memset(c,0,sizeof(c));
            memset(b,0,sizeof(b));
            cin>>s;
            int ans = 0;
            if(s=="START"){
                cin>>n;
                for(int i=0;i<n;i++)
                    cin>>a[i];
                int sum = 0;
                for(int i=0;i<5;i++){
                    cin>>b[i];
                }
                cin>>s4;
                    fu();
                    //cout<<21<<endl;
                memset(cnt,0,sizeof(cnt));
                for(int i=0;i<n;i++){
                    memset(vis,0,sizeof(vis));
                    if(dfs(i))
                        ans++;
                }
                if(ans==n)
                    cout<<"T-shirts rock!"<<endl;
                else
                    cout<<"I'd rather not wear a shirt anyway..."<<endl;
            }
            else
                break;
        }
        return 0;
    }
  • 相关阅读:
    Jetty开发指导:WebSocket介绍
    Python处理JSON
    聚焦数据可视化之中的一个--沃尔马怎样利用数据可视化依据实时社交数据调整採购和仓储计划?
    刚刚在寻找微博
    2010级信管毕业生实习总结汇编版(共29份)
    推荐杀毒软件
    Windows Server 2008 R2 下载地址
    在myeclipse中使用log4j记录日志
    获取Tomcat更详细的日志
    java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory
  • 原文地址:https://www.cnblogs.com/kls123/p/7778635.html
Copyright © 2011-2022 走看看