zoukankan      html  css  js  c++  java
  • 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 }
     
  • 相关阅读:
    Linux学习--------二
    Linux学习--------一
    PHP的回调函数
    妙用PHP函数处理数组
    MySQL错误码大全
    godoc使用方法介绍
    JS处理数据四舍五入(tofixed与round的区别详解)
    laravel手动数组分页
    PhpStorm+Xdebug配置单步调试PHP
    设计函数时,要考虑的因素
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/7242539.html
Copyright © 2011-2022 走看看