• Technocup 2017


    The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S,M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this size.

    During the registration, the organizers asked each of the n participants about the t-shirt size he wants. If a participant hesitated between two sizes, he could specify two neighboring sizes — this means that any of these two sizes suits him.

    Write a program that will determine whether it is possible to present a t-shirt to each participant of the competition, or not. Of course, each participant should get a t-shirt of proper size:

    • the size he wanted, if he specified one size;
    • any of the two neibouring sizes, if he specified two sizes.

    If it is possible, the program should find any valid distribution of the t-shirts.

    Input

    The first line of the input contains six non-negative integers — the number of t-shirts of each size. The numbers are given for the sizes S, M, L,XL, XXL, XXXL, respectively. The total number of t-shirts doesn't exceed 100 000.

    The second line contains positive integer n (1 ≤ n ≤ 100 000) — the number of participants.

    The following n lines contain the sizes specified by the participants, one line per participant. The i-th line contains information provided by the i-th participant: single size or two sizes separated by comma (without any spaces). If there are two sizes, the sizes are written in increasing order. It is guaranteed that two sizes separated by comma are neighboring.

    Output

    If it is not possible to present a t-shirt to each participant, print «NO» (without quotes).

    Otherwise, print n + 1 lines. In the first line print «YES» (without quotes). In the following n lines print the t-shirt sizes the orginizers should give to participants, one per line. The order of the participants should be the same as in the input.

    If there are multiple solutions, print any of them.

    Examples
    input
    0 1 0 1 1 0
    3
    XL
    S,M
    XL,XXL
    output
    YES
    XL
    M
    XXL
    input
    1 1 2 0 1 1
    5
    S
    M
    S,M
    XXL,XXXL
    XL,XXL
    output
    NO
    题意:那个有6种不同的衣服。有些人尺码确定的,有些人则位于中间,比如XL~XXL,问怎么分配
    解法:
    1 优先分配单独的
    2 两种选择的优先权是"S,M","M,L","L,XL","XL,XXL","XXL,XXXL",(高->低)
    3 然后...其实就这样,再改改输出就行
    4 当时认为是剩余多的先选WA到死
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 map<string,int>Mp,mp;
     4 int a[10];
     5 string s[100010];
     6 string s2[100010];
     7 string s3[7]={" ","S","M","L","XL","XXL","XXXL"};
     8 string ss[6]={" ","S,M","M,L","L,XL","XL,XXL","XXL,XXXL"};
     9 vector<string>Ve;
    10 int main(){
    11     mp["S"]=1;
    12     mp["M"]=2;
    13     mp["L"]=3;
    14     mp["XL"]=4;
    15     mp["XXL"]=5;
    16     mp["XXXL"]=6;
    17     Mp["S,M"]=1;
    18     Mp["M,L"]=2;
    19     Mp["L,XL"]=3;
    20     Mp["XL,XXL"]=4;
    21     Mp["XXL,XXXL"]=5;
    22     for(int i=1;i<=6;i++){
    23         cin>>a[i];
    24     } //cout<<a[mp["XXL"]]<<endl;
    25     int m;
    26     cin>>m;
    27     for(int i=1;i<=m;i++){
    28         cin>>s[i];
    29         if(Mp[s[i]]==0){
    30             a[mp[s[i]]]--;
    31         }
    32     }
    33     for(int i=1;i<=6;i++){
    34             if(a[i]<0){
    35                 cout<<"NO"<<endl;
    36                 return 0;
    37             }
    38         }
    39     for(int i=1;i<=5;i++){
    40         for(int j=1;j<=m;j++){
    41             if(ss[i]==s[j]){
    42                 if(a[Mp[s[j]]]){
    43                     a[Mp[s[j]]]--;
    44                     s[j]=s3[Mp[s[j]]];
    45                 }else if(a[Mp[s[j]]+1]){
    46                     a[Mp[s[j]]+1]--;
    47                     s[j]=s3[Mp[s[j]]+1];
    48                 }else{
    49                     cout<<"NO"<<endl;
    50                     return 0;
    51                 }
    52             }
    53         }
    54     }
    55     cout<<"YES"<<endl;
    56     for(int i=1;i<=m;i++){
    57         cout<<s[i]<<endl;
    58     }
    59     return 0;
    60 }
     
  • 相关阅读:
    L3-015. 球队“食物链”【DFS + 剪枝】
    L3-002. 堆栈【主席树 or 线段树 or 分块】
    PTA L1-006 连续因子【暴力模拟】
    【路由和交换之H3C自导自演】
    【ospf-stub区域配置】
    【ospf-链路验证】
    【ospf-vlink虚拟连接】
    【c学习-14】
    【c学习-13】
    【php学习-5】
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/7242539.html
Copyright © 2020-2023  润新知