zoukankan      html  css  js  c++  java
  • 2020-2021 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules) C. Berpizza (STL)

    • 题意:酒吧里有两个服务员,每个人每次都只能服务一名客人,服务员2按照客人进酒吧的顺序服务,服务员3按照客人的钱来服务,询问(q),(1)表示有客人进入酒吧,带着(m)块钱,(2)表示询问服务员2当前应该服务的客人编号,(3)表示服务员3当前应该服务的客人编号.
    • 题解:搞两个set,第一个set存pair,存编号和钱,用重载运算符来模拟排序,第二个set只存编号,然后模拟乱搞就行.
    • 代码:
    #include <bits/stdc++.h>
    #define ll long long
    #define fi first
    #define se second
    #define pb push_back
    #define me memset
    #define rep(a,b,c) for(int a=b;a<=c;++a)
    #define per(a,b,c) for(int a=b;a>=c;--a)
    const int N = 1e6 + 10;
    const int mod = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    using namespace std;
    typedef pair<int,int> PII;
    typedef pair<ll,ll> PLL;
    ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
    ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
    
    int q;
    
    struct misaka{
    	bool operator () (const PII &a,const PII &b) const{
    		if(a.fi!=b.fi) return a.fi>b.fi;
    		return a.se<b.se;
    	}
    };
    
    set<PII,misaka> q1;
    set<int> q2;
    int cnt[N];
    int op;
    int x;
    
    int main() {
        ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    	cin>>q;
    
    	int idx=0;
    
    	while(q--){
    		cin>>op;
    		if(op==1){
    			cin>>x;					
    			cnt[++idx]=x;
    			q1.insert(make_pair(x,idx));
    			q2.insert(idx);
    		}
    		else if(op==2){
    			int cur=*q2.begin();
    			q2.erase(cur);
    			q1.erase(make_pair(cnt[cur],cur));
    			cout<<cur<<' ';
    		}
    		else{
    			auto tmp=*q1.begin();
    			int cur=tmp.se;
    			q1.erase(tmp);
    			q2.erase(cur);
    			cout<<cur<<' ';
    		}
    	}
    
        return 0;
    }
    
    
  • 相关阅读:
    api接口统一管理
    axios封装
    事件监听和事件模型
    W3C标准
    Redis安装(PHPredis服务+windows的redis环境)
    Redis介绍
    jQuery ajax方法小结
    博客园鼠标特效
    PHP---截取七牛地址中的文件名
    jQuery---显示和隐藏
  • 原文地址:https://www.cnblogs.com/lr599909928/p/14195302.html
Copyright © 2011-2022 走看看