JAG Practice2016-C-We don't wanna work!-模拟

https://acm.bnu.edu.cn/v3/statments/jag2016.pdf


无脑大模拟啊。。。


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;
const int N=100005;
typedef long long ll;

struct node
{
    int x,ti,ran;
    node(int a,int b,int c)
    {
        x=a,ti=b,ran=c;
    }
    bool operator<(const node &b)const
    {
        if (ran!=b.ran)
            return ran<b.ran;
        return ti<b.ti;
    }
};
map<string,int>mp;
map<int,string>rev;
int rankk[N];
int tttt[N];
set<node>sb;
set<node>working;
set<node>::iterator it;
int vis[100000+50];
int main()
{

    // freopen("out","w",stdout);
    int n;
    cin>>n;
    int id=0;
    char tmp[100];
    string ss;
    int v;
    for (int i=1; i<=n; i++)
    {
        scanf("%s%d",tmp,&v);
        ss=tmp;
        if (mp[ss]==0)
            mp[ss]=++id,rev[id]=ss;
        rankk[ mp[ss]]=v,tttt[mp[ss]]=i;
        sb.insert(node(mp[ss],i,v));
    }

    int tot=n;
    int need=tot/5;
    int cun=1;
    it=sb.end();
    it--;
    for (; cun<=need;)
    {
        int id=it->x;
        vis[id]=1,working.insert(node(id,tttt[id],rankk[id]));
        it--;
        cun++;
        sb.erase(node(id,tttt[id],rankk[id]));
    }
    int m;
    cin>>m;
    char tmp2[100];
    char stmp[100];
    getchar();
    for (int i=1; i<=m; i++)
    {
        gets(stmp);
        int ret= sscanf(stmp,"%s%s%d",tmp2,tmp,&v);
        ss=tmp;
        if (mp[ss]==0)
            mp[ss]=++id,rev[id]=ss;
        if (ret==3)
        {
        rankk[ mp[ss]]=v,tttt[mp[ss]]=i+n;
            node newpeo(mp[ss],i+n,v);
            tot++;
            int nd=(tot)/5;
            if (nd==need)
            {
                if (!working.empty())
                {

                    node minn=*working.begin();
                    if (minn<newpeo)
                    {
                        printf("%s is working hard now.\n",ss.c_str());
                        printf("%s is not working now.\n",rev[working.begin()->x].c_str());
                        vis[working.begin()->x]=0;
                        sb.insert(*working.begin());
                        working.erase(working.begin());
                        working.insert(newpeo);
                        vis[newpeo.x]=1;
                        continue;
                    }
                     sb.insert(newpeo);
                    printf("%s is not working now.\n",ss.c_str());
                }
                else
                {
                    
                    sb.insert(newpeo);
                 printf("%s is not working now.\n",ss.c_str());
                }
                continue;
            }
            need=nd;
            sb.insert(newpeo);
            it=sb.end();
            it--;
            vis[it->x]=1;
            if (it->x!=newpeo.x)     printf("%s is not working now.\n",ss.c_str());
            printf("%s is working hard now.\n",rev[it->x].c_str());
            working.insert(*it);
            sb.erase(it);

        }
        else
        {
            tot--;
            int id=mp[ss];

            int nd=tot/5;
            if (nd==need)
            {
                if (vis[id]==1)
                {
                  //  printf("%s is not working now.\n",rev[id].c_str());
                    vis[id]=0 ;
                    working.erase(node(id,tttt[id],rankk[id]) );
                    it=sb.end();
                    it--;
                    vis[it->x]=1;
                    printf("%s is working hard now.\n",rev[it->x].c_str());
                    working.insert(*it);
                    sb.erase(it);
                }
                else
                    sb.erase(node(id,tttt[id],rankk[id]) );
                continue;
            }
            need=nd;
            if (vis[id]==1)
            {
                //printf("%s is not working now.\n",rev[id].c_str());
                vis[id]=0 ;
                working.erase(node(id,tttt[id],rankk[id]) );
            }
            else
            {
                sb.erase(node(id,tttt[id],rankk[id]));
                vis[id]=0;
                node minn=*working.begin();
                printf("%s is not working now.\n",rev[working.begin()->x].c_str());
                vis[minn.x]=0;
                sb.insert(minn);
                working.erase(working.begin());

            }


        }

    }


    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值