• 【codeforces 727D】Tshirts Distribution


    【题目链接】:http://codeforces.com/problemset/problem/727/D

    【题意】

    给你6种尺寸的衣服;
    他们的尺码依次为S, M, L, XL, XXL, XXXL;
    给你每种衣服的件数;
    以及每个人想要的衣服种类;
    (但有些人可能不知道自己要的是哪一种衣服,则他们对这相邻的两种衣服都接受)
    然后让你去分配这6种衣服;
    让每个人都满意;

    【题解】

    对于单个选择的;直接让他们满意;
    给他们想要的;
    对于相邻选择的;
    考虑”S,M”,”M,L”,”L,XL”,”XL,XXL”,”XXL,XXXL”
    可以看到S只有一种人要,其他的人都不会要S了
    所以对于选择S、M的,
    优先把S衣服给它;
    如果S不够了,再分M的;
    如果不行、就无解;
    这样我们又把S、M的排除掉了,
    对于剩下的
    “M,L”,”L,XL”,”XL,XXL”,”XXL,XXXL”
    M也只有一种人要;
    则对于M、L也优先分配M;
    不足的再用L补
    很棒的贪心

    【Number Of WA

    0

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define ms(x,y) memset(x,y,sizeof x)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    const int N = 1e5+100;
    const string idx[11]={"S","M","L","XL","XXL","XXXL","S,M","M,L","L,XL","XL,XXL","XXL,XXXL"};
    
    int now[6],n,p[N],ans[N];
    string s;
    
    int zzk(string t)
    {
        rep1(i,0,10)
            if (idx[i]==t)
                return i;
    }
    
    int main()
    {
        //freopen("F:\\rush.txt","r",stdin);
        ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not use
        rep1(i,0,5) cin>>now[i];
        cin>>n;
        rep1(i,1,n)
        {
            cin >> s;
            rep1(j,0,10)
                if (s == idx[j])
                    p[i] = j;
        }
        rep1(i,1,n)
            if (p[i]<=5)
            {
                if (now[p[i]])
                {
                    now[p[i]]--;
                    ans[i] = p[i];
                }
                else
                    return cout << "NO"<<endl,0;
            }
        rep1(k,6,10)
        {
            int pos = idx[k].find(',',0);
            int p1 = zzk(idx[k].substr(0,pos)),p2 = zzk(idx[k].substr(pos+1,10));
            //cout <<p1<<' '<<p2<<endl;
            rep1(i,1,n)
                if (p[i]==k)
                {
                    if (now[p1])
                    {
                        now[p1]--;
                        ans[i] = p1;
                        continue;
                    }
                    if (now[p2])
                    {
                        now[p2]--;
                        ans[i] = p2;
                        continue;
                    }
                    return cout << "NO"<<endl,0;
                }
        }
        cout <<"YES"<<endl;
        rep1(i,1,n)
            cout << idx[ans[i]] << endl;
        return 0;
    }
  • 相关阅读:
    教育网玩QQ游戏解决办法
    国家重点实验室分布<转>
    MySQL存储过程错误No data zero rows fetched, selected, or processed
    安装Oracle Developer后 pl sql无法使用
    Jsp开发入门
    开源项目MiniOA协同办公系统介绍
    JavaScript实现网页单击事件
    (转)普及基础知识一
    “人脸识别程序”总结
    (转)如何加速Altera的EDA工具? (IC Design) (Quartus II) (Nios II) (SOPC Builder)
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626330.html
Copyright © 2020-2023  润新知