• 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;
    }
    
  • 相关阅读:
    记录cacti时间筛选bug的解决办法
    mysql开启远程访问权限
    Mysql 5.7.32 安装cacti-0.8.8h出错
    记录Apache无法解析PHP代码解决方法
    zabbix5.0安装问题:Time zone for PHP is not set
    数据库以及数据表的创建
    小程序框架wepy
    通用的代码总结
    html网页什么样的字体最好看,css设置各种中文字体样式代码
    vue中使用BetterScroll(网上)
  • 原文地址:https://www.cnblogs.com/Basasuya/p/8433739.html
Copyright © 2020-2023  润新知