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.\n",nam[i]);
                        s2.insert(t2);
                    }else {
                        printf("%s is working hard now.\n",nam[i]);
                        printf("%s is not working now.\n",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.\n",nam[i]);
                        s1.insert(t2);
                    }else {
                        printf("%s is not working now.\n",nam[i]);
                        printf("%s is working hard now.\n",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.\n",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.\n",nam[t2.id]);
                    s2.erase(it); s1.insert(t2);
                }

            }
        }
    }
    return 0;
}
posted @ 2016-10-05 19:24  basasuya  阅读(144)  评论(0编辑  收藏  举报