zoukankan      html  css  js  c++  java
  • 2020年团体程序设计天梯赛 L2-2 口罩发放

    思路:

    首先建一个全局vector存有相关症状的人,再建一个局部vector存每一天的申请信息,排序后进行筛选。

    Tip:

    操作顺序:

    1. 检查身份证合法性
    2. 对于有相关症状的人员进行记录
    3. 排序
    4. 按照规则发放口罩

    任何一步顺序都不能调换和丢失,否则本题无法通过。

    #include <bits/stdc++.h>
    
    using namespace std;
    typedef long long ll;
    const int maxn = 1000 + 5;
    const int INF = 0x7FFFFFFF;
    
    struct mmp {
        string name;
        string idcard;
        int shen;
        int times;
        int index;
    };
    
    map<string, int> mp;
    set<string> smp;
    set<string> vHave;
    vector<mmp> v;
    
    bool cmp(mmp a, mmp b) {
        if (a.times == b.times)
            return a.index < b.index;
        return a.times < b.times;
    }
    
    int main() {
        int D, P;
        scanf("%d %d", &D, &P);
        for (int day = 1; day <= D; day++) {
            int ti, si;
            cin >> ti >> si;
            vector<mmp> use;
            for (int i = 1; i <= ti; i++) {
                string name;
                string idcard;
                int shen;
                int hh;
                int mm;
                cin >> name;
                cin >> idcard;
                cin >> shen;
                scanf("%d:%d", &hh, &mm);
                bool flag = true;
                if (idcard.length() != 18)
                    continue;
                for (auto j:idcard)
                    if (!(j >= '0' && j <= '9'))
                        flag = false;
                if (flag) {
                    if (shen && vHave.find(idcard) == vHave.end()) {
                        v.push_back(mmp{name, idcard, shen, hh * 60 + mm, i});
                        vHave.insert(idcard);
                    }
                    use.push_back(mmp{name, idcard, shen, hh * 60 + mm, i});
                }
            }
            sort(use.begin(), use.end(), cmp);
            int now = 0;
            for (int i = 0; i < use.size() && now < si; i++) {
                if (mp[use[i].idcard] == 0 || day >= P + mp[use[i].idcard] + 1) {
                    now++;
                    mp[use[i].idcard] = day;
                    cout << use[i].name << " " << use[i].idcard << endl;
                }
            }
        }
        for (auto i:v)
            cout << i.name << " " << i.idcard << endl;
        return 0;
    }
    

      

  • 相关阅读:
    不务正业系列-浅谈《过气堡垒》,一个RTS玩家的视角
    [LeetCode] 54. Spiral Matrix
    [LeetCode] 40. Combination Sum II
    138. Copy List with Random Pointer
    310. Minimum Height Trees
    4. Median of Two Sorted Arrays
    153. Find Minimum in Rotated Sorted Array
    33. Search in Rotated Sorted Array
    35. Search Insert Position
    278. First Bad Version
  • 原文地址:https://www.cnblogs.com/Whiteying/p/14056499.html
Copyright © 2011-2022 走看看