We don't wanna work!

We don't wanna work!

[I Asia 2016]

Two set, a representative of the work, not the work of a representative of

It is actually a very simple simulation, but I actually sort numbers before. . . .

Check the code time to start from scratch check. .

#include <bits/stdc++.h>
 
using namespace std;
const int maxn = 1e5+7;
struct node
{
    char s[25];
    int ti,fen;
    bool operator<(const node&r)const
    {
        if(fen==r.fen)
        {
            return ti>r.ti;
        }
        return fen>r.fen;
    }
} s[maxn],tmp;
set<node>st,stt;
set<node>::iterator it;
map<string,int>mp;
char str[25];
char op[5];
int p;
void solve()
{
    if(st.size()>p)
    {
        it=st.end();
        --it;
        tmp=*it;
        cout<<tmp.s<<" is not working now."<<endl;
        st.erase(tmp);
        stt.insert(tmp);
    }
    else if(st.size()<p)
    {
        it=stt.begin();
        tmp=*it;
        cout<<tmp.s<<" is working hard now."<<endl;
        stt.erase(tmp);
        st.insert(tmp);
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int cnt=0,tag=0,k;
    p=n*0.2;
    for(int i=1; i<=n; ++i)
    {
        cin>>s[i].s>>k;
        s[i].fen=k;
        s[i].ti=i;
    }
    sort(s+1,s+1+n);
    for(int i=1; i<=n; ++i)
    {
        mp[s[i].s]=++cnt;
        tag++;
        if(i<=p)
        {
            st.insert(s[i]);
        }
        else
        {
            stt.insert(s[i]);
        }
    }
    int m;
    cin>>m;
    int id;
    while(m--)
    {
        cin>>op;
        tag++;
        if(op[0]=='+')
        {
            n++;
            p=n*0.2;
            cin>> str>>k;
            if(mp.count(str))
            {
                id=mp[str];
                s[id].ti=tag;
                s[id].fen=k;
            }
            else
            {
                mp[str]=++cnt;
                s[cnt].fen=k;
                s[cnt].ti=tag;
                strcpy(s[cnt].s,str);
                id=cnt;
            }
            if(st.empty())
            {
                if(p>0&&k>=(*stt.begin()).fen)
                {
                    st.insert(s[id]);
                    cout<<s[id].s<<" is working hard now."<<endl;
                }
                else
                {
                    stt.insert(s[id]);
                    cout<<s[id].s<<" is not working now."<<endl;
                }
            }
            else
            {
                it=st.end();
                --it;
                if(k>=(*it).fen||(st.size()<p&&k>=(*stt.begin()).fen))
                {
                    st.insert(s[id]);
                    cout<<s[id].s<<" is working hard now."<<endl;
                }
                else
                {
                    stt.insert(s[id]);
                    cout<<s[id].s<<" is not working now."<<endl;
                }
            }
            solve();
        }
        else
        {
            n--;
            p=n*0.2;
            cin>>str;
            id=mp[str];
            if(st.find(s[id])!=st.end())
            {
                st.erase(s[id]);
            }
            else
            {
                stt.erase(s[id]);
            }
            solve();
        }
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/smallocean/p/11518400.html