zoukankan      html  css  js  c++  java
  • 2016弱校联盟十一专场10.3,BNU52308,大模拟

    大模拟
    时限60s
    你没有看错
    是s不是ms

    https://www.bnuoj.com/v3/problem_show.php?pid=52308

    开两个set
    一个是前面20%
    一个是后面80%
    然后就在两个set的边界处操作
    = =
    操作,好烦啊啊啊啊啊啊啊啊 啊啊啊

    还有种写法是开两个map类似

    无论哪一种,代码量都大的可怕= =
    HH用map写了150行
    cdm用map写了200行(听说4个map)

    从下午四点开始写
    一开始用map写,写了100+行,样例调了半天,秒WA
    调到10点,气哭
    后来听zm说可以用两个set,似乎好写一点
    然后再写,再WA,再换写法,再发现之前少了一句。。。
    终于,发现评测机跑了10s以上基本就是过了
    不是因为网速卡,因为,时限有60s= =!

    以后写模拟题还是要细心啊,诶,好累

    #include <set>
    #include <map>
    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    const int N = 100007;
    struct node{
        string name;
        int val,time;
        void read(int x){time = x;cin>>name>>val;}
        bool operator < (const node &a)const{
            return val!=a.val?val>a.val:time>a.time;
        }
    }arr[N];
    int n;
    map<string,int>val;
    map<string,int>tim;
    set <node> work;
    set <node> rest;
    set<node>::iterator it;
    void newGuy(string st,int time){
        n++;
        int x;scanf("%d",&x);
        node tmp,newguy = node{st,x,time};
        val[st] = x; tim[st] = time ;
        it=rest.begin(); tmp = (*it);
        if ((work.size()+1)*5<=n){
            if (newguy<tmp){
                work.insert(newguy);
                cout<<newguy.name<<" is working hard now."<<endl;
            }else {
                rest.insert(newguy);
                cout<<newguy.name<<" is not working now."<<endl;
                rest.erase(tmp);
                work.insert(tmp);
                cout<<tmp.name<<" is working hard now."<<endl;
            }
        }else {
            if (work.empty()){
                rest.insert(newguy);
                cout<<newguy.name<<" is not working now."<<endl;
            }else {
                it = work.end(); it--;
                tmp = (*it);
                if (newguy<tmp){
                    work.insert(newguy);
                    work.erase(tmp);
                    rest.insert(tmp);
                    cout<<newguy.name<<" is working hard now."<<endl;
                    cout<<tmp.name<<" is not working now."<<endl;
                }else {
                    rest.insert(newguy);
                    cout<<newguy.name<<" is not working now."<<endl;
                }
            }
        }
    }
    void leave(string st){
        n--;
        node tmp,leaveguy=node{st,val[st],tim[st]};
        if (work.find(leaveguy)!=work.end()){
            work.erase(leaveguy);
            if ((work.size()+1)*5<=n){
                it = rest.begin();
                tmp = (*it);
                rest.erase(tmp);
                work.insert(tmp);
                cout<<tmp.name<<" is working hard now."<<endl;
            }
        }else {
            rest.erase(leaveguy);
            if ((work.size()+1)*5<=n){
                it = rest.begin();
                tmp = (*it);
                rest.erase(tmp);
                work.insert(tmp);
                cout<<tmp.name<<" is working hard now."<<endl;
            }else if (work.size()*5>n&&!work.empty()){
                it = work.end();it--;
                tmp = (*it);
                work.erase(tmp);
                rest.insert(tmp);
                cout<<tmp.name<<" is not working now."<<endl;
            }
        }
    }
    int main(){
        for (int m;cin>>n;){
            work.clear() ;
            rest.clear() ;
            for (int i=1;i<=n;i++) arr[i].read(i-n);
            sort( arr+1, arr+n+1) ;
            for (int i=1;i<=n;i++){
                node tmp = arr[i];
                val[tmp.name] = tmp.val ;
                tim[tmp.name] = tmp.time;
                if (i<=(int)(n/5.0))work.insert(arr[i]);
                else rest.insert(arr[i]);
            }
            char ch;string st;
            scanf("%d",&m);
            for (int i=1;i<=m;i++){
                cin>>ch>>st;
                if (ch=='+')newGuy(st,i);
                else leave(st);
            }
        }
        return 0;
    }
    
  • 相关阅读:
    spring MVC fromeWork 與webwork2 mvc 比較
    JAVA Oauth 认证服务器的搭建
    HTTPS的工作原理
    理解HTTP幂等性
    支付交易一般性准则
    设计模式六大原则
    腾讯微信技术总监周颢:一亿用户增长背后的架构秘密
    Valid Parentheses
    4Sum
    Letter Combinations of a Phone Number
  • 原文地址:https://www.cnblogs.com/cww97/p/12349377.html
Copyright © 2011-2022 走看看