zoukankan      html  css  js  c++  java
  • 2016弱校联盟十一专场10.3 We don't wanna work!

    能把 not working now 写成 not working hard now
    还查一晚上也是没谁了
    我的做法是维护两个set 分别是前20% 和后80%

    #include<iostream>
    #include<algorithm>
    #include<set>
    #include<cmath>
    #include<map>
    #include<cstdio>
    using namespace std;
    #define sz(X) ((int)X.size())
    int N,M;
    char nam[70005][25];
    map<string, int> mp;
    struct Node{
        int id; int val; int ti;
        Node(int a=0, int b=0, int c=0):id(a),val(b),ti(c){}
        bool operator < (const Node &v) const{
            if(val != v.val) return val > v.val;
            return ti > v.ti;
        }
        bool operator == (Node v) const{
            return id==v.id && val==v.val && ti==v.ti;
        }
    }mem[70005];
    set<Node> s1; set<Node> s2;
    set<Node>::iterator it1,it,it2;
    
    int main(){ 
        while(~scanf("%d",&N)) {
            mp.clear();
            s1.clear(); s2.clear();
            for(int i = 0; i < N; ++i) {
                int a; scanf("%s %d",nam[i], &a);
                s2.insert(Node(i,a,i));
                mem[i] = Node(i,a,i);
                mp[nam[i]] = i;
            }
            int tot = N;
            int K = floor(N/5);
            while(K--) {
                it = s2.begin(); 
                Node y = *it;
                s2.erase(y);
                s1.insert(y);
            }
    
            scanf("%d",&M);
            for(int i = N; i < N+M; ++i) {
                char s[5]; scanf("%s",s); 
                if(s[0] == '+') {
                    int a; scanf("%s %d",nam[i],&a);
                    Node tt = Node(i,a,i);
                    mem[i] = tt; mp[nam[i]] = i;
                    tot ++;
                    int x = floor(tot/5); int y = tot-x;
    
                    if(sz(s2) == y-1) {
                        s1.insert(tt);
                        it = --s1.end();  Node t2 = *it; s1.erase(it);
                        if(t2 == tt) {
                            printf("%s is not working now.
    ",nam[i]);
                            s2.insert(t2);
                        }else {
                            printf("%s is working hard now.
    ",nam[i]);
                            printf("%s is not working now.
    ",nam[t2.id]);
                            s2.insert(t2); 
                        }
                    }else {
                        s2.insert(tt);
                        it = s2.begin(); Node t2 = *it; s2.erase(it);
                        if(t2 == tt) {
                            printf("%s is working hard now.
    ",nam[i]);
                            s1.insert(t2);
                        }else {
                            printf("%s is not working now.
    ",nam[i]);
                            printf("%s is working hard now.
    ",nam[t2.id]);
                            s1.insert(t2);
                        }
                    }
    
                }else if(s[0] == '-') {
                    char _s[25];
                    scanf("%s",_s);
                    Node tt = mem[mp[_s]]; 
                    it1 = s1.find(tt); it2 = s2.find(tt);
                    if(it1 != s1.end()) s1.erase(it1); 
                    else s2.erase(it2);
                    tot--;
                    int x = floor(tot/5); int y = tot-x;
                    if(sz(s1) > x) {
                        it = --s1.end(); Node t2 = *it;
                        printf("%s is not working now.
    ",nam[t2.id]);
                        s1.erase(it); s2.insert(t2);
                    } 
                    if(sz(s2) > y) {
                        it = s2.begin(); Node t2 = *it;
                        printf("%s is working hard now.
    ",nam[t2.id]);
                        s2.erase(it); s1.insert(t2);
                    }
    
                }
            }
        }
        return 0;
    }
    
  • 相关阅读:
    leetcode刷题笔记四十四 通配符匹配
    leetcode刷题笔记四十三 字符串相乘
    leetcode刷题笔记四十二 接雨水
    Scala 学习 -- 其他集合类学习
    Scala 学习 -- 列表
    leetcode刷题笔记四十一 缺失的第一个正数
    HTML5每日一练之OL列表的改良
    HTML5边玩边学(1)画布实现方法
    html5 +css3 第一章学习和笔记
    HTML5每日一练之figure新标签的应用
  • 原文地址:https://www.cnblogs.com/Basasuya/p/8433739.html
Copyright © 2011-2022 走看看